Skip to main content
added 64 characters in body
Source Link
Joey
  • 13.2k
  • 2
  • 43
  • 73

for loops can have anything between 0 and three statements in their header:

Endless loop:

for(){}

Loop with initialization:

for($n=0){}

Loop with initialization and end condition:

for($n=0;$n-lt7){}

In such cases the additional semicolons at the end may be omitted (something that isn't pointed outit's explicitly stated in any published grammar of the language, sadlylanguage specification, but helpful for golfing nonethelessso it's not an implementation detail) in contrast to C-like languages which always require exactly three statements.

This also makes while a bit shorter. Compare

while(...){}

and

for(;...){}

With the added bonus that you can stick in a previous line (if there is one) into the for as well without extra cost (and even saving a character).

for loops can have anything between 0 and three statements in their header:

Endless loop:

for(){}

Loop with initialization:

for($n=0){}

Loop with initialization and end condition:

for($n=0;$n-lt7){}

In such cases the additional semicolons at the end may be omitted (something that isn't pointed out in any published grammar of the language, sadly, but helpful for golfing nonetheless) in contrast to C-like languages which always require exactly three statements.

This also makes while a bit shorter. Compare

while(...){}

and

for(;...){}

With the added bonus that you can stick in a previous line (if there is one) into the for as well without extra cost.

for loops can have anything between 0 and three statements in their header:

Endless loop:

for(){}

Loop with initialization:

for($n=0){}

Loop with initialization and end condition:

for($n=0;$n-lt7){}

In such cases the additional semicolons at the end may be omitted (it's explicitly stated in the language specification, so it's not an implementation detail) in contrast to C-like languages which always require exactly three statements.

This also makes while a bit shorter. Compare

while(...){}

and

for(;...){}

With the added bonus that you can stick in a previous line (if there is one) into the for as well without extra cost (and even saving a character).

added 219 characters in body
Source Link
Joey
  • 13.2k
  • 2
  • 43
  • 73

for loops can have anything between 0 and three statements in their header:

Endless loop:

for(){}

Loop with initialization:

for($n=0){}

Loop with initialization and end condition:

for($n=0;$n-lt7){}

In such cases the additional semicolons at the end may be omitted (something that isn't pointed out in any published grammar of the language, sadly, but helpful for golfing nonetheless) in contrast to C-like languages which always require exactly three statements.

This also makes while a bit shorter. Compare

while(...){}

and

for(;...){}

With the added bonus that you can stick in a previous line (if there is one) into the for as well without extra cost.

for loops can have anything between 0 and three statements in their header:

Endless loop:

for(){}

Loop with initialization:

for($n=0){}

Loop with initialization and end condition:

for($n=0;$n-lt7){}

In such cases the additional semicolons at the end may be omitted (something that isn't pointed out in any published grammar of the language, sadly, but helpful for golfing nonetheless) in contrast to C-like languages which always require exactly three statements.

for loops can have anything between 0 and three statements in their header:

Endless loop:

for(){}

Loop with initialization:

for($n=0){}

Loop with initialization and end condition:

for($n=0;$n-lt7){}

In such cases the additional semicolons at the end may be omitted (something that isn't pointed out in any published grammar of the language, sadly, but helpful for golfing nonetheless) in contrast to C-like languages which always require exactly three statements.

This also makes while a bit shorter. Compare

while(...){}

and

for(;...){}

With the added bonus that you can stick in a previous line (if there is one) into the for as well without extra cost.

Source Link
Joey
  • 13.2k
  • 2
  • 43
  • 73

for loops can have anything between 0 and three statements in their header:

Endless loop:

for(){}

Loop with initialization:

for($n=0){}

Loop with initialization and end condition:

for($n=0;$n-lt7){}

In such cases the additional semicolons at the end may be omitted (something that isn't pointed out in any published grammar of the language, sadly, but helpful for golfing nonetheless) in contrast to C-like languages which always require exactly three statements.