I didn't understand the part about initializing more than one value in statement 1 of 'for' loops. Any help is appreciated | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 2

I didn't understand the part about initializing more than one value in statement 1 of 'for' loops. Any help is appreciated

8th Feb 2018, 9:46 PM
Ted Ariaga
3 Antworten
+ 7
The comma is a separator. You are limited in the places it is legal in Java. You can separate variable definitions, method call arguments, method definition parameters, and for loop statements in the initialization or increment to separate expressions. In the for loop, you can think of the comma as a semicolon. It does the same job there as the semicolon in normal usage. Of course, you couldn't use an actual semicolon there because they are used to separate the three for loop expressions.
8th Feb 2018, 10:45 PM
John Wells
John Wells - avatar
+ 1
For example instead of needing two separate loops with one nested inside the other you could do for(x = 0, y = 0; x < max && y < max; x++, y ++) { print x * y } Note this is basically in pseudo-code though; not all languages support the comma operator and there may be another way to do this in your language of choice.
8th Feb 2018, 9:55 PM
Tom Shaver
Tom Shaver - avatar
+ 1
Thanks a lot....that's what I thought initially. I just got confused with d syntax that was used to explain it
8th Feb 2018, 10:17 PM
Ted Ariaga