Why use loops?


#1



why use loops? Unexpected token class


I don't see where anything needs to be changed and when I run it, I get unexpected token class.


Replace this line with your code. 
// Write five console.log statements.

public class print{
    public static void main (String[] args)
    
    console.log1 = {1};
    console.log2 = {2};
    console.log3 = {3};
    console.log4 = {4};
    console.log5 = {5};
    
    System.out.println (console.log(1), console.log(2), console.log(3), console.log(4), console.log(5));
    
}


#2

I'm confused. Parts of this look like Java, and parts look like Javascript...


#3

O.k. Im taking a java class and am totally confused so I started using this to help me out. Aren't they the same (don't get mad at me for asking!)?


#4

oum yes this is correct you can write a work many time in many line and run that without no error, but see this,

if you want print 1 to 1000, you write 1000 line code for print?

if in here forcing you to use loop just is for know how and when should use. usually, when a work want run more than 3 time is better to use loop because this is easily for develope code after , or know what was doing your codes is faster ,...

loop is good :wink:

use loop to this code and run it, i don't know java and javascript fully, sorry if not your answer, but this answer of

why use loops?


#5

Nope. They are very different. There is a Java course though, I suggest you take that.


#6

This is the code I used, and it works.

console.log(1);
console.log(2);
console.log(3);
console.log(4);
console.log(5);


#7

As @firstboy000 already mentioned think about doing the same for the task to print 1000 lines or even a million lines. And then think about doing all this with barely 3 lines of code and you should see how mighty loops are.