• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 14:01
CEST 20:01
KST 03:01
  • 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
[ASL21] Ro24 Preview Pt2: News Flash10[ASL21] Ro24 Preview Pt1: New Chaos0Team Liquid Map Contest #22 - Presented by Monster Energy18ByuL: The Forgotten Master of ZvT30Behind the Blue - Team Liquid History Book20
Community News
Weekly Cups (March 23-29): herO takes triple6Aligulac acquired by REPLAYMAN.com/Stego Research8Weekly Cups (March 16-22): herO doubles, Cure surprises3Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool51Weekly Cups (March 9-15): herO, Clem, ByuN win4
StarCraft 2
General
Rongyi Cup S3 - Preview & Info Team Liquid Map Contest #22 - Presented by Monster Energy Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool What mix of new & old maps do you want in the next ladder pool? (SC2) Aligulac acquired by REPLAYMAN.com/Stego Research
Tourneys
RSL Season 4 announced for March-April Sparkling Tuna Cup - Weekly Open Tournament StarCraft Evolution League (SC Evo Biweekly) WardiTV Mondays World University TeamLeague (500$+) | Signups Open
Strategy
Custom Maps
[M] (2) Frigid Storage Publishing has been re-enabled! [Feb 24th 2026]
External Content
The PondCast: SC2 News & Results Mutation # 520 Moving Fees Mutation # 519 Inner Power Mutation # 518 Radiation Zone
Brood War
General
ASL21 General Discussion Gypsy to Korea so ive been playing broodwar for a week straight. Pros React To: JaeDong vs Queen BSL 22 Map Contest — Submissions OPEN to March 10
Tourneys
[ASL21] Ro24 Group F Escore Tournament StarCraft Season 2 [Megathread] Daily Proleagues [ASL21] Ro24 Group E
Strategy
What's the deal with APM & what's its true value Fighting Spirit mining rates Simple Questions, Simple Answers
Other Games
General Games
Stormgate/Frost Giant Megathread Starcraft Tabletop Miniature Game Nintendo Switch Thread General RTS Discussion Thread Darkest Dungeon
Dota 2
The Story of Wings Gaming Official 'what is Dota anymore' discussion
League of Legends
G2 just beat GenG in First stand
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Mafia Game Mode Feedback/Ideas TL Mafia Community Thread Five o'clock TL Mafia
Community
General
US Politics Mega-thread The Chess Thread Russo-Ukrainian War Thread NASA and the Private Sector Things Aren’t Peaceful in Palestine
Fan Clubs
The IdrA Fan Club
Media & Entertainment
[Manga] One Piece [Req][Books] Good Fantasy/SciFi books Movie Discussion!
Sports
2024 - 2026 Football Thread Formula 1 Discussion Cricket [SPORT] Tokyo Olympics 2021 Thread General nutrition recommendations
World Cup 2022
Tech Support
[G] How to Block Livestream Ads
TL Community
The Automated Ban List
Blogs
Broowar part 2
qwaykee
China Uses Video Games to Sh…
TrAiDoS
Funny Nicknames
LUCKY_NOOB
Iranian anarchists: organize…
XenOsky
FS++
Kraekkling
ASL S21 English Commentary…
namkraft
Electronics
mantequilla
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1478 users

The Big Programming Thread - Page 202

Forum Index > General Forum
Post a Reply
Prev 1 200 201 202 203 204 1032 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 States17281 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 States17281 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
Germany2594 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
Germany2594 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
Germany2594 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 1032 Next
Please log in or register to reply.
Live Events Refresh
Next event in 14h 59m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
ProTech143
Railgan 67
StarCraft: Brood War
Calm 4321
Mind 668
Horang2 579
actioN 297
Hyuk 148
Dewaltoss 111
Sexy 37
Movie 33
Hm[arnc] 24
yabsab 20
[ Show more ]
GoRush 18
Terrorterran 13
soO 13
ajuk12(nOOB) 11
NaDa 8
Dota 2
Gorgc5698
qojqva3387
420jenkins335
Counter-Strike
fl0m3446
zeus467
edward70
Heroes of the Storm
Khaldor183
MindelVK17
Other Games
Grubby2294
FrodaN1753
Beastyqt693
ArmadaUGS128
Livibee71
Trikslyr70
C9.Mang054
Organizations
StarCraft 2
angryscii 22
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 18 non-featured ]
StarCraft 2
• Adnapsc2 21
• Reevou 2
• intothetv
• Kozan
• sooper7s
• Migwel
• AfreecaTV YouTube
• LaughNgamezSOOP
• IndyKCrew
StarCraft: Brood War
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• WagamamaTV756
• lizZardDota267
League of Legends
• Nemesis1807
• Jankos1703
Other Games
• imaqtpie764
• Shiphtur199
Upcoming Events
CranKy Ducklings
14h 59m
Sparkling Tuna Cup
15h 59m
PiGosaur Cup
1d 5h
Replay Cast
1d 14h
Kung Fu Cup
1d 17h
Replay Cast
2 days
The PondCast
2 days
CranKy Ducklings
3 days
WardiTV Team League
3 days
Replay Cast
4 days
[ Show More ]
CranKy Ducklings
4 days
WardiTV Team League
4 days
uThermal 2v2 Circuit
4 days
BSL
5 days
Sparkling Tuna Cup
5 days
WardiTV Team League
5 days
BSL
6 days
Replay Cast
6 days
Replay Cast
6 days
Wardi Open
6 days
Liquipedia Results

Completed

Escore Tournament S2: W1
RSL Revival: Season 4
NationLESS Cup

Ongoing

BSL Season 22
CSL Elite League 2026
ASL Season 21
CSL Season 20: Qualifier 2
CSL 2026 SPRING (S20)
StarCraft2 Community Team League 2026 Spring
Nations Cup 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026

Upcoming

Escore Tournament S2: W2
IPSL Spring 2026
Escore Tournament S2: W3
Acropolis #4
BSL 22 Non-Korean Championship
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
uThermal 2v2 Last Chance Qualifiers 2026
RSL Revival: Season 5
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026
BLAST Rivals Spring 2026
CCT Season 3 Global Finals
IEM Rio 2026
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 © 2026 TLnet. All Rights Reserved.