• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 21:37
CEST 03:37
KST 10:37
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
[ASL20] Ro24 Preview Pt2: Take-Off7[ASL20] Ro24 Preview Pt1: Runway132v2 & SC: Evo Complete: Weekend Double Feature4Team Liquid Map Contest #21 - Presented by Monster Energy9uThermal's 2v2 Tour: $15,000 Main Event18
Community News
Weekly Cups (Aug 18-24): herO dethrones MaxPax6Maestros of The Game—$20k event w/ live finals in Paris31Weekly Cups (Aug 11-17): MaxPax triples again!13Weekly Cups (Aug 4-10): MaxPax wins a triple6SC2's Safe House 2 - October 18 & 195
StarCraft 2
General
#2: Serral - Greatest Players of All Time #1: Maru - Greatest Players of All Time I hope balance council is prepping final balance Geoff 'iNcontroL' Robinson has passed away Aligulac - Europe takes the podium
Tourneys
Esports World Cup 2025 Sparkling Tuna Cup - Weekly Open Tournament Maestros of The Game—$20k event w/ live finals in Paris WardiTV Mondays RSL: Revival, a new crowdfunded tournament series
Strategy
Custom Maps
External Content
Mutation # 488 What Goes Around Mutation # 487 Think Fast Mutation # 486 Watch the Skies Mutation # 485 Death from Below
Brood War
General
BSL Polish World Championship 2025 20-21 September BGH Auto Balance -> http://bghmmr.eu/ ASL Season 20 Ro24 Groups Flash On His 2010 "God" Form, Mind Games, vs JD No Rain in ASL20?
Tourneys
[Megathread] Daily Proleagues [IPSL] CSLAN Review and CSLPRO Reimagined! [ASL20] Ro24 Group F [ASL20] Ro24 Group D
Strategy
Simple Questions, Simple Answers Fighting Spirit mining rates [G] Mineral Boosting Muta micro map competition
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread General RTS Discussion Thread Dawn of War IV Path of Exile
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine The year 2050 European Politico-economics QA Mega-thread
Fan Clubs
INnoVation Fan Club SKT1 Classic Fan Club!
Media & Entertainment
Anime Discussion Thread Movie Discussion! [Manga] One Piece [\m/] Heavy Metal Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
High temperatures on bridge(s) Gtx660 graphics card replacement Installation of Windows 10 suck at "just a moment"
TL Community
The Automated Ban List TeamLiquid Team Shirt On Sale
Blogs
RTS Design in Hypercoven
a11
Evil Gacha Games and the…
ffswowsucks
Breaking the Meta: Non-Stand…
TrAiDoS
INDEPENDIENTE LA CTM
XenOsky
[Girl blog} My fema…
artosisisthebest
Sharpening the Filtration…
frozenclaw
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1202 users

The Big Programming Thread - Page 202

Forum Index > General Forum
Post a Reply
Prev 1 200 201 202 203 204 1031 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
Snuggles
Profile Blog Joined May 2010
United States1865 Posts
November 26 2012 04:00 GMT
#4021
Did my professor just indirectly call my code a piece of crap? It was just a math computation code to figure out the calculation of a bunch of square roots to 625, you'll see what I mean when you see the code (python btw).

My writing
# TN
# 5.37

import math

# set variables
uno = 1
dos = 2

i = math.sqrt(uno)
k = math.sqrt(dos)
counter = 625

total = 1 / (i / k)

# loop

while counter > 0 :
uno += 1
dos += 1
total += 1 / (i / k)
counter -= 1

print('The sum of the computation is','%.01f' % total)



Professor's code

# DZ
# Summation

# SETUP
import math
total = 0

# NO INPUT, JUST COMPUTE
for i in range (1, 625):
total += 1 / (math.sqrt (i) + math.sqrt (i + 1))

# OUTPUT
print (total)


"(5.37) Everything but the loop is incorrect." is the exact e-mail I got from him.
Craton
Profile Blog Joined December 2009
United States17250 Posts
Last Edited: 2012-11-26 04:22:44
November 26 2012 04:10 GMT
#4022
There's a difference between writing good code and writing code that works. Python especially tends to be about succinctness and simplicity, whereas your code has many unnecessary variables and lines.

You've over-complicated something that should be a simple bit of code and made it harder to read and maintain than necessary. Additionally, you don't gain any forward-looking functionality/expandability out of your solution that would warrant the maintainability/readability cost.

All of your variables are poorly named, to boot. They all have no meaning about how they're used or what they contain. i and k are typically used as increment variables, but you've halfway used them as temporary storage for calculated values.

Also, while I don't know Python, I don't believe your logic inside the loop would work. The first time you use i and k you call the math.sqrt of the function on them, but every subsequent time inside the loop you're simply using the same i and k (look at your code and tell me where you do anything to i or k inside your loop or where you use uno or dos after incrementing).

Basically, your loop doesn't do what you want.
twitch.tv/cratonz
frogmelter
Profile Blog Joined April 2009
United States971 Posts
November 26 2012 04:33 GMT
#4023
Snuggles:

Variables i and k are never updated within the loop. Therefore the same value is being added to total at every iteration.

Your professor's code has a for i in range (1, 625) loop, where i will increase by one after every iteration. Therefore, the value that will be added to total will be different every iteration.

Those are the main differences between your code and his code.

If you moved

i = math.sqrt(uno)
k = math.sqrt(dos)


into the loop it would probably work.

However, you wrote a lot of code to emulate the style of a for loop. Why not just use a for loop directly?
TL+ Member
Lukaskr
Profile Joined December 2011
Poland9 Posts
Last Edited: 2012-11-26 06:58:02
November 26 2012 05:09 GMT
#4024
Was wondering if anyone could help me with HW on discrete math. My professor is seriously on crack, HW averages are like 55%.

Ok, so first of all if someone could explain what does it mean to use a combinatorial proof to prove something. I googled about it, but honestly it was really hard to understand and see how it applies to my problem.

In first part of her question it is like this,
Use binomial theorem to prove:
C(n,0)+C(n,1)2+C(n,2)2^2+...+C(n,n)2^n=3^n

So I recognized it as binomial theorem, of a=2,b=1, substitued left side of the equation for
(2+1)^n and said (2+1)^n=3^n

How can I prove the same thing using combinatorial counting argument?



Not rly programming but Discrete Math is at the very foundation of computing...
If you do not think there is anything worth dying for, you have nothing to live for.
Craton
Profile Blog Joined December 2009
United States17250 Posts
November 26 2012 05:30 GMT
#4025
This is explicitly a thread where you don't ask "here's my homework, help"

If you want help, figure out things yourself and then ask for help on specific sticking points.
twitch.tv/cratonz
AmericanUmlaut
Profile Blog Joined November 2010
Germany2577 Posts
Last Edited: 2012-11-26 13:09:27
November 26 2012 13:09 GMT
#4026
On November 26 2012 13:00 Snuggles wrote:
Did my professor just indirectly call my code a piece of crap?

Yes, and you should write him a thank you note for letting you know in such a friendly manner. Computer programming is really hard, and if you're going to succeed at it, you need a much better developed sense of perfectionism than that function demonstrates. I can see that it's just a beginner project, so it's completely fine that your code is awful, but it's also important that you understand that the code is wrong both logically and stylistically, and demonstrates that you're not thinking about how to write a program the right way.

So the first problem is, your program is wrong. What was your testing process? I'm guessing you didn't test your result for correctness at all, or you would have noticed the error. Testing the actual calculation would be a lot of work, so my testing process would have been something like: Replace the 625 with 5, work out the answer by hand, see if your code produces the right answer for 5. Once you get it working for 5, test it again with another value. Once you know that the function generates the correct values for a set of testable numbers, you can deduce that it should work for larger numbers, as well.

The second problem was already pretty well explained by everyone else: Your code has a whole bunch of extra bits and doodads that are completely unnecessary, and your variable names are meaningless. This sort of criticism is something that beginners in CS tend to think is just crotchety old people being crotchety, because when you're starting out you write programs that are maybe two pages of code, and you have to "maintain" them for the weekend it takes you to write them. I work on projects with lifetimes around ten years and tens to hundreds of thousands of lines of code, and I have been in the unenviable position of having to fire people who thought that writing legible and maintainable code was a waste of time, because I don't have time to figure out what "uno" meant to someone else three years ago, and he probably doesn't remember anymore, either.

Don't get discouraged, though. Everyone wrote shitty code in the beginning. The important thing is that you understand what it is that makes your code bad, and focus on not making the same mistakes in your next project.
The frumious Bandersnatch
heishe
Profile Blog Joined June 2009
Germany2284 Posts
Last Edited: 2012-11-26 14:10:11
November 26 2012 14:06 GMT
#4027
On November 26 2012 22:09 AmericanUmlaut wrote:

Don't get discouraged, though. Everyone wrote writes shitty code in the beginning. The important thing is that you understand what it is that makes your code bad, and focus on not making the same mistakes in your next project.


I fixed this statement, because I think it's important for a beginner to know that there is probably not a single programmer in the world, no matter how experienced or intelligent, that doesn't write shitty code sometimes for legitimate reasons (e.g. they just can't think of better ways to do it at that specific moment).

Programming is just too complex for that. Arguably it's one, if the not the, most complex engineering field out there. The degrees of freedom of any software application is just larger than those that you'd potentially find in other fields, and to make it worse, math doesn't help to provide clear cut answers most of the time.
If you value your soul, never look into the eye of a horse. Your soul will forever be lost in the void of the horse.
AmericanUmlaut
Profile Blog Joined November 2010
Germany2577 Posts
November 26 2012 14:38 GMT
#4028
On November 26 2012 23:06 heishe wrote:
Show nested quote +
On November 26 2012 22:09 AmericanUmlaut wrote:

Don't get discouraged, though. Everyone wrote writes shitty code in the beginning. The important thing is that you understand what it is that makes your code bad, and focus on not making the same mistakes in your next project.


I fixed this statement, because I think it's important for a beginner to know that there is probably not a single programmer in the world, no matter how experienced or intelligent, that doesn't write shitty code sometimes for legitimate reasons (e.g. they just can't think of better ways to do it at that specific moment).

Programming is just too complex for that. Arguably it's one, if the not the, most complex engineering field out there. The degrees of freedom of any software application is just larger than those that you'd potentially find in other fields, and to make it worse, math doesn't help to provide clear cut answers most of the time.

I salute you, sir, for you are very, very correct. I have, in fact, not yet reached a point where I wasn't embarassed to read my own code half a year or so after I wrote it: You learn so much so quickly in this field that you're basically always discovering what an ignorant fool you are, and how badly the cutting-edge code you thought you were writing yesterday actually sucked.
The frumious Bandersnatch
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2012-11-26 15:20:56
November 26 2012 15:19 GMT
#4029
Very true on all counts. People will bash on you even if you get the problem right if it's too inefficient, if it's not maintainable, if it's not portable, if it's not scalable. Getting the right answer isn't even half the problem most of the time.


I remember writing 30 lines of really shitty, simple code in Python for an interview. I got back home, wrote it in 25 lines. 4 months later, I wrote it in 3. As you improve, you actually get to see your improvement, which is one of the best parts of programming really. You get to see yourself solve problems you had no idea how to solve an hour ago, a week ago, a month ago, a couple years ago. It's really really really satisfying.

The real objective is just to always improve yourself, constantly learn, and never think that you're definitely right about something.

When you see your code from 1 year ago, you should go, "oh damn, I'm a dumb ass for writing that." And then you should simultaneously go, "wow, I love how much improvement I'm making and how much I'm learning."
There is no one like you in the universe.
Snuggles
Profile Blog Joined May 2010
United States1865 Posts
November 26 2012 17:45 GMT
#4030
Wow thanks guys. I'm very open to criticism, especially for programming. I gotta say I have the hardest time wrapping my head around the programs our professor wants us to do for the week so I appreciate all the input from you guys to see what is wrong with the way writing my code.

So what I got from you guys so far is-
1. Make my variables more reasonable and relevant
2. Make it more readable
3. Keep it simple
4. Test my program more thoroughly

I don't know why I didn't just use a for loop rather than while... I even remember that the Professor said that you should use a for loop if you know exactly how many iterations you need and a while loop if that's a dependent variable.

So to make my code more readable does that mean just reducing the amount of unnecessary variables and simplifying the code in general? Is there any form of given etiquette in the style so that my Professor doesn't squint his eyes or something?

btw it's gonna be embarrassing as hell to face my professor now today... and we're getting exams back so I'm worried as hell lol.
Ame
Profile Joined October 2009
United States246 Posts
November 26 2012 18:36 GMT
#4031
Does anyone have a for loop off the top of their head that cannot be written as a while loop? Or the opposite? Internet said while loops work with booleans better... but for loops initialized and terminated fine with booleans when I did a test run in Java.

Is it more of a convention thing then? Such that when another programmer comes in and sees a while or for loop they can then they can make a quick assumption on the check being dependent or not?
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2012-11-26 19:07:07
November 26 2012 19:04 GMT
#4032
On November 27 2012 02:45 Snuggles wrote:
Wow thanks guys. I'm very open to criticism, especially for programming. I gotta say I have the hardest time wrapping my head around the programs our professor wants us to do for the week so I appreciate all the input from you guys to see what is wrong with the way writing my code.

So what I got from you guys so far is-
1. Make my variables more reasonable and relevant
2. Make it more readable
3. Keep it simple
4. Test my program more thoroughly

I don't know why I didn't just use a for loop rather than while... I even remember that the Professor said that you should use a for loop if you know exactly how many iterations you need and a while loop if that's a dependent variable.

So to make my code more readable does that mean just reducing the amount of unnecessary variables and simplifying the code in general? Is there any form of given etiquette in the style so that my Professor doesn't squint his eyes or something?

btw it's gonna be embarrassing as hell to face my professor now today... and we're getting exams back so I'm worried as hell lol.


Indentation (4 spaces usually or 1 'tab' if you use Notepad++) and programming conventions in general. E.g. my Java lecturer wants me to write constants like this:

private static final double PI = 3.14; (notice caps)

Read further:
http://en.wikipedia.org/wiki/Coding_conventions
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
Last Edited: 2012-11-26 19:11:50
November 26 2012 19:09 GMT
#4033
On November 27 2012 03:36 Ame wrote:
Does anyone have a for loop off the top of their head that cannot be written as a while loop? Or the opposite? Internet said while loops work with booleans better... but for loops initialized and terminated fine with booleans when I did a test run in Java.

Is it more of a convention thing then? Such that when another programmer comes in and sees a while or for loop they can then they can make a quick assumption on the check being dependent or not?


I'm not exactly sure what you're getting at here. A for loop is the same as a while loop with some additional organizational structure for clarity's sake.

Back in old programming (BASIC/Pascal) days, they were used for seperate purposes, so convention has followed. For loops are used as loops that iterate a known number of times before the loop is encountered, whereas while loops are more of a "keep doing this until..." kind of statement.


i=0;
while(i<10) {
//do stuff
++i;
}

for(i=0;i<10;++i) {
//do stuff
}
Any sufficiently advanced technology is indistinguishable from magic
Ame
Profile Joined October 2009
United States246 Posts
November 26 2012 19:28 GMT
#4034
On November 27 2012 04:09 RoyGBiv_13 wrote:
Show nested quote +
On November 27 2012 03:36 Ame wrote:
Does anyone have a for loop off the top of their head that cannot be written as a while loop? Or the opposite? Internet said while loops work with booleans better... but for loops initialized and terminated fine with booleans when I did a test run in Java.

Is it more of a convention thing then? Such that when another programmer comes in and sees a while or for loop they can then they can make a quick assumption on the check being dependent or not?


I'm not exactly sure what you're getting at here. A for loop is the same as a while loop with some additional organizational structure for clarity's sake.

Back in old programming (BASIC/Pascal) days, they were used for seperate purposes, so convention has followed. For loops are used as loops that iterate a known number of times before the loop is encountered, whereas while loops are more of a "keep doing this until..." kind of statement.


i=0;
while(i<10) {
//do stuff
++i;
}

for(i=0;i<10;++i) {
//do stuff
}


I guess I'm looking for... reasoning for why both For and While loops even exist, instead of just one of them. If there is actually something that can be done in one of the loops that the other cannot do without the addition with many lines of code. Maybe For and While loops hit memory in different way (noob here, no idea how heap/stack/whatnot work)?

Otherwise the answer seems to be something vestigial that is just coding conventions now?
frogmelter
Profile Blog Joined April 2009
United States971 Posts
November 26 2012 19:40 GMT
#4035
On November 27 2012 03:36 Ame wrote:
Does anyone have a for loop off the top of their head that cannot be written as a while loop? Or the opposite? Internet said while loops work with booleans better... but for loops initialized and terminated fine with booleans when I did a test run in Java.

Is it more of a convention thing then? Such that when another programmer comes in and sees a while or for loop they can then they can make a quick assumption on the check being dependent or not?


For loops require less lines of code for the same thing a while loop does. Also, the counter variable can be automatically deallocated when the loop ends. But no, here is no for loop that can not be written as a while loop that I know of. A for loop is just a while loop with an initialzer and a statement that runs at the end of every iteration.
TL+ Member
Nick3
Profile Joined March 2011
513 Posts
November 26 2012 19:41 GMT
#4036
On November 27 2012 04:28 Ame wrote:
Show nested quote +
On November 27 2012 04:09 RoyGBiv_13 wrote:
On November 27 2012 03:36 Ame wrote:
Does anyone have a for loop off the top of their head that cannot be written as a while loop? Or the opposite? Internet said while loops work with booleans better... but for loops initialized and terminated fine with booleans when I did a test run in Java.

Is it more of a convention thing then? Such that when another programmer comes in and sees a while or for loop they can then they can make a quick assumption on the check being dependent or not?


I'm not exactly sure what you're getting at here. A for loop is the same as a while loop with some additional organizational structure for clarity's sake.

Back in old programming (BASIC/Pascal) days, they were used for seperate purposes, so convention has followed. For loops are used as loops that iterate a known number of times before the loop is encountered, whereas while loops are more of a "keep doing this until..." kind of statement.


i=0;
while(i<10) {
//do stuff
++i;
}

for(i=0;i<10;++i) {
//do stuff
}


I guess I'm looking for... reasoning for why both For and While loops even exist, instead of just one of them. If there is actually something that can be done in one of the loops that the other cannot do without the addition with many lines of code. Maybe For and While loops hit memory in different way (noob here, no idea how heap/stack/whatnot work)?

Otherwise the answer seems to be something vestigial that is just coding conventions now?


A for and while loop that does the same thing will in most compilers get the same representation when its compiled to bytecode, machine code etc. Essentially for loops can be viewed as special case syntactic sugar for while loops.
WhuazGoodJaggah
Profile Blog Joined January 2009
Lesotho777 Posts
Last Edited: 2012-11-26 19:59:09
November 26 2012 19:58 GMT
#4037
for loops are traditionally for things like a defined number of iterations (walking through an array) where while loops are used for indefinit number of iterations (reading lines of a file until there is nothing left)

so you get:

for(int i=0; i<arrayElements;i++){
take element doggy style;
}

while(NOT EOF){
read that dirty next line;
}


this is why I personally FUCKING HATE endless for loops, it's butt ugly.
small dicks have great firepower
AmericanUmlaut
Profile Blog Joined November 2010
Germany2577 Posts
Last Edited: 2012-11-26 20:13:03
November 26 2012 20:08 GMT
#4038
On November 27 2012 04:28 Ame wrote:
Show nested quote +
On November 27 2012 04:09 RoyGBiv_13 wrote:
On November 27 2012 03:36 Ame wrote:
Does anyone have a for loop off the top of their head that cannot be written as a while loop? Or the opposite? Internet said while loops work with booleans better... but for loops initialized and terminated fine with booleans when I did a test run in Java.

Is it more of a convention thing then? Such that when another programmer comes in and sees a while or for loop they can then they can make a quick assumption on the check being dependent or not?


I'm not exactly sure what you're getting at here. A for loop is the same as a while loop with some additional organizational structure for clarity's sake.

Back in old programming (BASIC/Pascal) days, they were used for seperate purposes, so convention has followed. For loops are used as loops that iterate a known number of times before the loop is encountered, whereas while loops are more of a "keep doing this until..." kind of statement.


i=0;
while(i<10) {
//do stuff
++i;
}

for(i=0;i<10;++i) {
//do stuff
}


I guess I'm looking for... reasoning for why both For and While loops even exist, instead of just one of them. If there is actually something that can be done in one of the loops that the other cannot do without the addition with many lines of code. Maybe For and While loops hit memory in different way (noob here, no idea how heap/stack/whatnot work)?

Otherwise the answer seems to be something vestigial that is just coding conventions now?

It's less a question of convention than a question of readability. If you see for(i=0; i<10; i++){...}, you instantly know what's intended without having to give it a lot of thought, whereas it takes a bit more thinking to parse a while loop that does the same thing (you have to go through the body of the loop and see everything that can happen to your i variable). While loops remain useful, though, because there are a lot of times when you don't have a number of loops you want to do, but rather you just want to loop until you encounter some stop condition, for example looping through a string and doing something with each character:

while(null !== curChar) {
curChar = myString.getNextChar();
doSomething(curChar);
}

You could technically do the same thing with a for loop, but it would be really unreadable. In fact, in terms of making a program work for and while loops could both be replaced by GOTO, which is what they devolve to at the machine code level in any case. We have these control structures not because they work better logically, but because they make code a lot more intuitive to read and write for humans. One of the most important concepts in programming as far as I'm concerned is understanding that writing code that a computer can understand (what 99% of people think we do for a living) is only the first part of the job, and is often relatively easy*. When you're good, you give as much consideration to making sure that you're writing code that a person can understand.

*Except for pointers and the Javascript SelectionRange object.

Edit to add: Another point is that for() gives you a really simple syntax for something that you do over and over and over again as a programmer. A while loop requires several lines of code to do the same thing, which multiplies your opportunites for typos, forgetting to initialize or increment your counter, and so on. One of the reasons that "elegance" is held holy by computer programmers is that if you can figure out a way to solve a problem with 3 lines of code rather than 20, then even if your 3 lines are no faster and no more logically correct than my 20, your code has only 3 things that can be wrong, and mine has 20. At the same time, if a bug in your code does pop up, the guy who gets the job of fixing it only has to understand 3 lines of code, so he'll probably be able to instantly or very quickly grasp what's being done, which might take significantly more time in a function that's much longer.
The frumious Bandersnatch
sAsThark
Profile Joined September 2011
France27 Posts
Last Edited: 2012-11-26 20:13:03
November 26 2012 20:10 GMT
#4039
On November 27 2012 04:09 RoyGBiv_13 wrote:
Show nested quote +
On November 27 2012 03:36 Ame wrote:
Does anyone have a for loop off the top of their head that cannot be written as a while loop? Or the opposite? Internet said while loops work with booleans better... but for loops initialized and terminated fine with booleans when I did a test run in Java.

Is it more of a convention thing then? Such that when another programmer comes in and sees a while or for loop they can then they can make a quick assumption on the check being dependent or not?


I'm not exactly sure what you're getting at here. A for loop is the same as a while loop with some additional organizational structure for clarity's sake.

Back in old programming (BASIC/Pascal) days, they were used for seperate purposes, so convention has followed. For loops are used as loops that iterate a known number of times before the loop is encountered, whereas while loops are more of a "keep doing this until..." kind of statement.


i=0;
while(i<10) {
//do stuff
++i;
}

for(i=0;i<10;++i) {
//do stuff
}


Yes, and in Java, you can also do a for each like things on an iterable class (your own wich return an iterator or one from Java API, for instance ArrayList).

for(Element e : myArrayList)
{
/*I do stuff with my e*/
}
while(myArrayList.hasNext())
{
Element e = mayArrayList.next()
/*GoTo previus comment*/
}
http://fedoraproject.org/
Ame
Profile Joined October 2009
United States246 Posts
Last Edited: 2012-11-26 20:28:17
November 26 2012 20:11 GMT
#4040
Haha, yes, I get the traditional/conventional reason. >_>

Didn't know the auto deallocate variable part, so I guess that's an additional line of code I didn't think of. Pah, noobs like me don't even deallocate anything to begin with. ... ;;

At the 'less lines of code bit', is it pretty much 3 less lines? Initialization, increment/change, deallocation?

Gotta run, thanks for the replies all. o/

*edit

Ahh, I'll probably take 'readability' as the biggest selling point.

I really need to read up on the stuff such as "for(Element e : myArrayList)". I see that : everywhereeee.

~~

@combinatorial problem: Well, despite it being discouraged but since I don't actually see the 'dont ask about homework' bit in the thread rules... here's in return for people having answered my questions. A guess because it's been forever since I've taken Discrete Math, but I'd wager it has something to do with writing out all the C(n,n) in equation forms and then canceling a lot of things out. Or some crafty substitutions.
Prev 1 200 201 202 203 204 1031 Next
Please log in or register to reply.
Live Events Refresh
Replay Cast
00:00
SEL S2 Championship: Ro16
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
PiGStarcraft188
SpeCial 137
ProTech79
RuFF_SC2 41
Nina 39
StarCraft: Brood War
Artosis 735
Sharp 48
Icarus 3
Beast 2
Dota 2
monkeys_forever946
League of Legends
JimRising 302
Counter-Strike
Stewie2K771
taco 190
Super Smash Bros
hungrybox506
Mew2King20
Other Games
tarik_tv13368
summit1g8554
Day[9].tv841
shahzam631
C9.Mang0319
ViBE213
Maynarde123
ROOTCatZ0
Organizations
StarCraft 2
CranKy Ducklings133
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 16 non-featured ]
StarCraft 2
• OhrlRock 1
• intothetv
• AfreecaTV YouTube
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• Azhi_Dahaki2
• iopq 1
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Doublelift4336
• Stunt267
Other Games
• Day9tv841
Upcoming Events
The PondCast
8h 23m
WardiTV Summer Champion…
9h 23m
herO vs MaxPax
Clem vs Classic
Replay Cast
22h 23m
LiuLi Cup
1d 9h
MaxPax vs TriGGeR
ByuN vs herO
Cure vs Rogue
Classic vs HeRoMaRinE
Cosmonarchy
1d 14h
OyAji vs Sziky
Sziky vs WolFix
WolFix vs OyAji
Big Brain Bouts
1d 14h
Iba vs GgMaChine
TriGGeR vs Bunny
Reynor vs Classic
Serral vs Clem
BSL Team Wars
1d 17h
Team Hawk vs Team Dewalt
BSL Team Wars
1d 17h
Team Hawk vs Team Bonyth
SC Evo League
2 days
TaeJa vs Cure
Rogue vs threepoint
ByuN vs Creator
MaNa vs Classic
Maestros of the Game
2 days
ShoWTimE vs Cham
GuMiho vs Ryung
Zoun vs Spirit
Rogue vs MaNa
[ Show More ]
[BSL 2025] Weekly
2 days
SC Evo League
3 days
Maestros of the Game
3 days
SHIN vs Creator
Astrea vs Lambo
Bunny vs SKillous
HeRoMaRinE vs TriGGeR
BSL Team Wars
3 days
Team Bonyth vs Team Sziky
BSL Team Wars
3 days
Team Dewalt vs Team Sziky
Monday Night Weeklies
4 days
Replay Cast
4 days
Sparkling Tuna Cup
5 days
Replay Cast
6 days
Liquipedia Results

Completed

CSL Season 18: Qualifier 1
uThermal 2v2 Main Event
HCC Europe

Ongoing

Copa Latinoamericana 4
BSL 20 Team Wars
KCM Race Survival 2025 Season 3
BSL 21 Qualifiers
ASL Season 20
Acropolis #4 - TS1
CSL Season 18: Qualifier 2
SEL Season 2 Championship
WardiTV Summer 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
BLAST.tv Austin Major 2025

Upcoming

CSL 2025 AUTUMN (S18)
LASL Season 20
BSL Season 21
BSL 21 Team A
Chzzk MurlocKing SC1 vs SC2 Cup #2
RSL Revival: Season 2
Maestros of the Game
EC S1
Sisters' Call Cup
Skyesports Masters 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
MESA Nomadic Masters Fall
Thunderpick World Champ.
CS Asia Championships 2025
Roobet Cup 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.