• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
makronik

Define loop?

5 posts in this topic

Hello. I recently started learning c++, though I decided to start python first in order to understand what is programming etc. in order to do that, can someone briefly explain with is a "loop" and give a situation and a example so that I understand it in basic terms. thanks :)
0

Share this post


Link to post
Share on other sites
Congrats [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img] I enjoy Python! it's pretty sweet [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img]

To me, a loop is obviously doing the same tasks over and over till a certain condition is met.

[CODE]
while count < 5:
Display "hotdogballoon"

Display "This is out of the loop"
[/CODE]

You could look at it as a teenager as well.

[CODE]
While age < 18:
Display "You can't buy cigs"

Display "Out of the loop"
[/CODE]

You are looping till a condition is met no matter what it is. Edited by Inuyashakagome16
1

Share this post


Link to post
Share on other sites
in basic terms a loop is a conditional setting for code within in the loop to continue to repeat execution.

say you want to count the number of 1's in an array (an array is just a simple "list" of data in successive memory)

int [50] myNum = { 1,2, 1, 3 1, ..... //fill in the rest with whatever you want}'

now lets count the number of 1's

int numOf1 = 0;
int indexOfArray = 0;
while (indexOfArray != 50) // this is a condition to stop the loop. when indexOfArray equals 50, the repeition of the following will stop
//everything in the brackets will be repeated as long as the above condition is true
{
if (myNum[indexOfArray] == 1)
numOf1++; //this counts the number of 1s

indexOfArray++; //this allows you to go to the next element in the array;
}


now it will first start off with both variables at 0; then it will run the code in the middle. indexOfArray will only be at 1 after the first run through, so indexOfArray !=50 will be true.

this will repeat the inner code 50 times, updating the variable everyloop; indexOfArray increments EVERY loop. while numOf1 only increments when it finds a 1 inside the array


if you just did this

while (true) {} this will run FOREVER because it is always true.
while (false) {...} this will NEVER run becuase it is always false

another example
index = 0;
while (myNum [index] != 1)
{ index++;}

now it will only stop when you find a 1 inside the myNum array. if there is no 1 it will run forever

sorry for not knowing python this is in C++ Edited by arkane7
0

Share this post


Link to post
Share on other sites
[quote name='arkane7' timestamp='1343929605' post='4965604']
in basic terms a loop is a conditional setting for code within in the loop to continue to repeat execution.

say you want to count the number of 1's in an array (an array is just a simple "list" of data in successive memory)

int [50] myNum = { 1,2, 1, 3 1, ..... //fill in the rest with whatever you want}'

now lets count the number of 1's

int numOf1 = 0;
int indexOfArray = 0;
while (indexOfArray != 50) // this is a condition to stop the loop. when indexOfArray equals 50, the repeition of the following will stop
//everything in the brackets will be repeated as long as the above condition is true
{
if (myNum[indexOfArray] == 1)
numOf1++; //this counts the number of 1s

indexOfArray++; //this allows you to go to the next element in the array;
}


now it will first start off with both variables at 0; then it will run the code in the middle. indexOfArray will only be at 1 after the first run through, so indexOfArray !=50 will be true.

this will repeat the inner code 50 times, updating the variable everyloop; indexOfArray increments EVERY loop. while numOf1 only increments when it finds a 1 inside the array


if you just did this

while (true) {} this will run FOREVER because it is always true.
while (false) {...} this will NEVER run becuase it is always false

another example
index = 0;
while (myNum [index] != 1)
{ index++;}

now it will only stop when you find a 1 inside the myNum array. if there is no 1 it will run forever

sorry for not knowing python this is in C++
[/quote] I'll start this once I done couple of tuts etc ;) at the moment I am just printing and use if , else statements . thanks for the info :)
0

Share this post


Link to post
Share on other sites
[quote name='Inuyashakagome16' timestamp='1343929491' post='4965602']
Congrats [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img] I enjoy Python! it's pretty sweet [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img]

To me, a loop is obviously doing the same tasks over and over till a certain condition is met.

[CODE]
while count < 5:
Display "hotdogballoon"

Display "This is out of the loop"
[/CODE]

You could look at it as a teenager as well.

[CODE]
While age < 18:
Display "You can't buy cigs"

Display "Out of the loop"
[/CODE]

You are looping till a condition is met no matter what it is.
[/quote] thanks :)
0

Share this post


Link to post
Share on other sites
Surprised he showed a while loop rather than a for loop, the for was always a bit easier to understand first time round for me.

[u]Python 2:[/u]
[source lang="python"]for count in range(0,5):
print count
print "not looping"[/source]

[u]Python 3:[/u]
[source lang="python"]for count in range(0,5):
print(count)
print('not looping')[/source]

Anyway, what happens here is when the program hits the "for count in range(x,y,step)" line it creates a new variable called count. This variable will have the value x (usually 0 or 1 although some programs you will have need for other numbers)
The program will then run the indented code which in this case is print count.
When it hits the end of the indented code block it adds the step value to count, you don't need to worry about step usually, if you leave it out (as I have above) python assumes its 1 instead. So when count was 0, it hits the end of the indent and adds 1 to count so count now = 1.
Python then checks to see if count is equal to y (in our case 5), if count is less than y then we loop again. If count is equal to y or greater than y (funny step values can cause that) then we don't loop anymore.

So the above program that we had with x and y as 0 and 5 respectively when run will output the following:
[quote name='program above']
0
1
2
3
4
not looping
[/quote]
Count starts off with a value of 0, we print that to the screen.
Then the loop automatically adds 1 to count. The loop automatically checks count is less than our y value and because it is we loop again.
Then when count eventually gets assigned a value of 5 the loop stops looping and we go onto the next line of code which outputs the text not looping.


I didn't know if you use python 2 or 3 so I gave both versions. Top is 2, bottom is 3. Edited by 6677
2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0