Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  for loop?  (Read 838 times)
0 Members and 1 Guest are viewing this topic.
Offline trollwarrior1
« Posted 2014-02-20 13:54:37 »

I tried googling something about this topic, but couldn't really phrase it properly.

I was staring at my code and started thinking about what does "for" in for loop stand for? I mean, it just doesn't make any sense to me Cheesy
Offline Troubleshoots

JGO Knight


Medals: 36
Exp: 7-9 months


Damn maths.


« Reply #1 - Posted 2014-02-20 14:10:37 »

Quote
The loop body is executed "for" the given values of the loop variable
http://en.wikipedia.org/wiki/For_loop

Why are all OpenGL tutorials written in Brainf**k?
Offline Roquen
« Reply #2 - Posted 2014-02-20 14:24:58 »

For each element in a set we do something.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Oskuro

JGO Knight


Medals: 39
Exp: 6 years


Coding in Style


« Reply #3 - Posted 2014-02-20 14:41:29 »

1  
for(int x = 0; x < 100; x++) { ... }

for an integer value x starting at 0, always smaller than 100, that increases in +1 per iteration, do stuff.

The for...each algorithm looks like this:

1  
for(string value : collection){ ... }

Which means, for each string in the collection, do stuff.

Offline quew8

JGO Coder


Medals: 29



« Reply #4 - Posted 2014-02-20 19:47:46 »

You can think of it as shorthand for a while loop, so:

1  
2  
3  
for(initialization; conditional; step) {
    action;
}

is the same as
1  
2  
3  
4  
5  
6  
7  
{
    initialization;
    while(conditional) {
        action;
        step;
    }
}

Obviously the for loop is more readable (especially for programmers) and more compact.
Offline trollwarrior1
« Reply #5 - Posted 2014-02-20 20:02:49 »

You can think of it as shorthand for a while loop, so:

1  
2  
3  
for(initialization; conditional; step) {
    action;
}

is the same as 
1  
2  
3  
4  
5  
6  
7  
{
    initialization;
    while(conditional) {
        action;
        step;
    }
}

Obviously the for loop is more readable (especially for programmers) and more compact.

I know that :O Was just thinking what for actual 'for' stand for. Already found my answer.
Offline quew8

JGO Coder


Medals: 29



« Reply #6 - Posted 2014-02-20 20:06:17 »

I wasn't trying to imply that you didn't know what a for loop did. I thought we were just posting our thoughts on the for loop.
Offline lcass
« Reply #7 - Posted 2014-02-23 23:22:40 »

For either means Forever until or For every in;

Example

foreveruntil(x = 0; x < 5;x++);   foreveryin(objecta:arrayb);
Offline Drenius
« Reply #8 - Posted 2014-02-24 17:39:43 »

Not foreveruntil but foreverwhile.
Pages: [1]
  ignore  |  Print  
 
 

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (11 views)
2014-07-24 01:59:36

Riven (9 views)
2014-07-23 21:16:32

Riven (11 views)
2014-07-23 21:07:15

Riven (12 views)
2014-07-23 20:56:16

ctomni231 (42 views)
2014-07-18 06:55:21

Zero Volt (38 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (34 views)
2014-07-16 23:30:00

Cero (49 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!