![]() |
C Foxtrot Comic
I was reading the Friday Oct. 8th Chicago Tribune and saw this funny Foxtrot comic.
http://images.ucomics.com/comics/ft/2003/ft031003.gif I wasn't sure if this would fit better in Humor, but I figured it would be more appreciated here. :D :D :D |
That's awesome. :lol:
|
I love it :)
man I could have use this back in 3ed grade....he could stand to tighten up that code a bit too ;) |
Nice, I need that right now
|
That was great.. thanks!
|
nice! that's one smart kid
|
Quote:
|
:) i did this in my second year in HS. Had to write,"I will not make chin music in class." 100 times... i convinced the teacher that i had actually typed it 100 times, since I had a diasy wheel printer.
After that.... everyone started doing it. I had started a trend, and he wasn't all that happy with it. He then only started to collect hand written only. |
I've got UNIX underpants!
no, wait, wrong strip. :) |
I got it and I don't understand coding.
Am I a genius all of a sudden? *looks around* Nope! :p Thanks, BuddyHawks, pretty funny stuff. |
Cynthique, that is pretty cool.. I never had a teacher make us do the repitition on computer.. It was always hand written :(
nice strip :) I always love fox trot |
he forgot the \n :p
|
hehe.. that's funny.. =)
|
LOL, good find! Agreed, he did forget the \n... :p :D
|
I should print that out and put it on somethin and show my programming concepts teacher...
Thanks a bunch |
Still nasty code. If he's only using the counter inside the for loop, should definitly be defined inside of it (assuming C++, and not C):
for ( int count = 0; count < 500; count++ ) Also, of course, the code in the strip's only going to print it 499 times. Think the teacher'll count 'em? |
Nah, it's C (stdio, not iostream) :)
Also, I believe it's running 500 times because he used <= instead of <. Good pick up on the '\n' though ... i totally missed that when i read this in the paper lol |
Quote:
Is it good when we catch stuff like this in a comic? |
lol
|
Hehehe... I've just started learning C++ but that was really funny.. Nice find!
|
actually, now that I look at it he forgot the braces { } in the for loop.
Jeebus, Jason is falling apart! ;) ps. My CSci prof loved it. |
Quote:
hey, juan, how would//should he tighten it up? |
C
Code:
#include <stdio.h> Code:
#include <iostream> Had to edit to make the includes show up. It was driving me nuts |
juanvaldes thats invalid C, plus making everything appear on one line isn't doing anything to affect code performance, but does make it harder to read.
adding braces is arguably neater to stop running the risk of a later programmer adding more lines and it not working as one might expect , but if its a finalized app its mainly syntactic sugar, though it is something i would recommend doing and do. He may have deliberately left out the \n as that would fill the entire stdout with the phrase. and they say programmers over analyze :) |
I did not mean to imply faster code, just shorter. A friend did one using a while loop with trinary operators in it just for the hell of it, pretty funny.
|
A little different but would this work as well?
Code:
#include <stdio.h> Had to edit to make the include show up |
Quote:
|
Yeah,
for whlie do while all the loops can be applied. |
Quote:
int i=500; while(i--) { ..... } simple, uses a faster test which is generally implemented as a single instruction, the whole loop can be done in one instruction on a pc (ignoring the inital load), though some optimizing compilers will pick up on that the for loop and fix it. |
Quote:
|
Quote:
count number of times printed 2 1 3 2 4 3 . . . 498 497 499 498 500 499 501 End of loop </pre> So you would only end up with the sentence being printed 499 times. |
hrdwareguy: nope, you are missing the key point,
2 to 501 is inclusive which equals 500 steps. example say it was i=1 to i<=5 instead of 500 so int i ; while (i<=5){ i++ }; program starts : i = 1 :loop starts is i less than or equal to 5 ? i=1, so yes, continue. i is incremented to 2 "message is printed' (1rst time) go back to top of loop is i less than or equal to 5 ? i=2 so yes, continue. i is incremented , is now 3 "message is printed' ( 2nd time) go back to top of loop is i less than or equal to 5 ? i=3 so yes, continue. i is incremented , is now 4 "message is printed' (3rd time) go back to top of loop is i less than or equal to 5 ? i=4 so yes, continue. i is incremented , is now 5 "message is printed' (4th time) go back to top of loop is i less than or equal to 5 ? i=5 so yes, continue. (not the key part here is less than *or* equal to 5 = 5 so its true, so it meets the condition. i is incremented , is now 6 "message is printed' (5th time) go to start of loop is i less than or equal to 5 ? i is now 6, so stop the loop since 6 <= 5 is false (0) 5 messages were printed. This is quite a common mistake made for junior or new programmers, its similar to people using the 5th element on an array defined as say int[5] and then using i = array[5]; which is of course the 6th element. |
Quote:
I understand this. The original code I was referring to did not say <= 501 it said <=500. Go back and look at it if you want to. Since the original code I was referring to was therefore 2 to 500, I still stand by my statement that it will only print 499 times. |
hrdwareguy: dear oh dear, please read over my comment
Quote:
For instance my example is 1 to 5 but it runs as 2 to 6. so when you do <=n , n ends up being + 1 i really don't know how to simplify it anymore so that you can understand it. So heres another proof (hope this posts correctly) i added my comments with a // to the actual session Code:
I could post the exe if you still don't believe me, but if you go over the loop i typed it in the previous comment it will be come obvious to you (since it does seem like you didn't read it through as the comment you made indicates you didn't see where i said <=500 twice) |
I'm never going to post any code in this forum again. :)
|
Charliex: OK, I get it, you are correct. I was getting getting confused because I usually increment my loops at the bottom. Got one to many tests in there.
By the way, I edited your post for the sole purpose of making the <stdio.h> display correctly. |
hrdwareguy-
How did you get it to include the #include? I tried like 3 different ways. Just curious. |
Code:
#include <stdio.h> It would still print 500 lines. |
Quote:
|
Actuall in my mind it was something like this:
Code:
#include <stdio.h> |
All times are GMT -8. The time now is 11:04 AM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project