[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip / qa] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology


Thread archived.
You cannot reply anymore.


[Advertise on 4chan]


File: forwhile.png (44 KB, 980x806)
44 KB
44 KB PNG
which is better and why
>>
>>96080290
they're the same.
it doesn't matter.
>>
>>96080290
for(;;) has less IL code so that's what I use.
>>
while(true) because it compiles to the same thing but is easier to understand at a glance than both of them
>>
>>96080290
while (1) because for (;;) looks like a tranime emoji
>>
while("" == [])
>>
>>96080371
>stdbool
bloat
>>
>>96080290
while (1=1);
>>
>>96080290
#define maybe if(rand() < RAND_MAX / 2
>>
>>96080290
Both suck ass use map and reduce
>>
>>96080290
Ada did it best with a special keyword for endless loops.
loop
stuff;
end loop;
>>
loop {
...
}
>>
>>96080392
Anime isn't tranny. Lack of anime is tranny. Simple as.
>>
>>96080290
When I see
while (1)
I think about the jews, because while (((1))).

When I see
for (;;)
I think about UOHHHHH CUNNY because ;;
>>
>>96080627
>>96080619
step aside
(loop ...)
>>
>>96080290
while (true.toString().toUppercase() === 'TRUE')
>>
both are stupid
>>96080579
>>96080619
>>96080645
are good. if you disagree you're a stockholm syndrome sepples victim
>>
>>96080433
Wake up grandpa, true is standard C23
>>
>>96080619
>>96080645
Rust trannies
>>
>>96080290
>>96080290
>>96080290
>>96080290
>>96080290
While for readability, unless you use a programming language like Go where the only keyword for loops is "for"
>>
>>96080290
goto
>>
All loops are while loops
>>
loop:
....
goto loop;
>>
compiles literally in the same way unless your compiler is written by (you)
>>
loop:
jmp loop
ret
>>
while ("true") {};
>>
>>96080933
while ("false");
>>
File: lisp_shield.png (191 KB, 400x400)
191 KB
191 KB PNG
>>96080761
>Rust
i'm a lispchad
>>
f() {
...
f()
}
>>
>>96080967
for ("niggers"; "tongue"; "my anus") {
}
>>
>>96080290
8 < 9
>>
>>96080290
let's see how many chads are in here
loop do

end
>>
File: 1664572226090158.png (32 KB, 398x398)
32 KB
32 KB PNG
>>96080395
based
>>
File: 1693923728264030.png (22 KB, 715x592)
22 KB
22 KB PNG
>>96080392
actually it's called "vampire operator"
>>
>>96080290
#define ever (;;)
for ever {
...
}
>>
>>96080910
call 2f
2:
...
sub [rsp], 5
ret
>>
>>96081118
while (--x)
>>
>>96081155
based
>>
>>96080392
Anime website
>>
>>96080290
for me, it's:
for (;;)
>>
>>
>>96080619
#define loop for (;;)

Seethe for me, white boy.
>>
>>96081524
does this count as zero cost abstraction
>>
>>96081600
Well I didn't pay anything for it.
>>
until(0)
>>
>>96080290
For for when you know your iterant. While for when you don't.
>>
File: macros.png (65 KB, 871x913)
65 KB
65 KB PNG
>>96081524
Sure, you can do that. But why stop there?
>>
>>96080392
>>96080627
>for (;;) is the pedophile one
ok this makes a lot of sense
>>
>>96080782
/thread
>>
File: bait.jpg (2.49 MB, 1462x2222)
2.49 MB
2.49 MB JPG
>>96080451
>>
>>96080290
do { } while (1); is best. It'll optimise to no instructions at all if the loop gets exited with break; before the end in the loop
>>
>>96080290
I've never even considered for(;;), I just go with while(true)
>>
>>96082584
Won't every optimizing compiler remove the check regardless?
>>
aren't we talking about peanuts here? all of these are fast
>>
>>96080290
for (;;) is more confusing for noobs so i prefer it. keeps the userspace small and elitist.
>>
>>96080290
function fun() {
// your code here
fun()
}
>>
>>96083061
TCOd and redpilled
>>
#include <iostream>

int trueFunction()
{
return -1;
}
char whileConditionEvaluator(int(*condition)())
{
if(condition())
return true;
return !true;
}
void whileBody()
{
std::cout<<'A';
}

void While(char (*condition)(int(*)()), int (*conditionFunction)(), void (*body)())
{
do
{
body();
}
while(condition(conditionFunction));
}
int main()
{
While(whileConditionEvaluator,trueFunction,whileBody);
return 1;
}
>>
>>96080290
I swear every time I see one of those in the wild it's there for some retarded reasons, and the break condition could just be the while condition.
>>
>>96080290
for(int i=1;i--;++i)
>>
>>96080290
while (op.isgay()) works very well.
>>
int D = 8;
while( 8==D )
>>
>>96080290
while(1) is always true forever. it is merely a convention that null statement evaluates to true.
>>
>>96080290
I don't code
>>
>endless loop
>still ends when a condition inside the loop itself is reached
why is this allowed
>>
>for (;;)
because the (;;) is a crying face which is cool
>>
>>96080746
>C(?!99|89)[0-9]{2}
Cringe
>>
>>96080290
>it's yet another episode of /g/'s baby tier programming discussion
let me guess next thread's gonna be about using if else or switch statements ... woah it's all so profound
>>
loop:
/* do stuff */
goto loop;
>>
void forever(void) {
do stuff;
forever();
}
>>
>>96080290
#define forever for(;;)
...
forever {
...
}
>>
for loops are just while loops in disguise anyway, and while loops are just gotos in disguise. which one to use depends on the language. anyone who says otherwise is a codelet and coping.
>>
>>96080290
>>96088434
Neither is correct. The most accurate method is to use while (true) as true is a single bit - the smallest possible unit of data that can be stored in an instruction.
>>
>>96088003
I wonder why we never have good discussions... oh wait, everyone here is a high schooler or college student
>>96088606
>>
>>96088677
Depends on the program and the school
I got into a decently good CS program and it's rather expected you know these things and the "bar" here is very high, they force you to take calc2 and linear algebra before you can really start pushing down the CS path. Most everyone here seems to be very comfortable with any given language whether it be Java, Cpp, or Rust. And I guess I'm one of them, in my algo class they taught it in cpp but I was side by side implementing everything in Java as well because that's fun to me.

Anyway it really is amazing the difference between a school like this and others that people go to. At this point of my education I've realized I will have no problem getting a job, the level of rigor that goes in at these places is no bullshit, it's been one of the hardest times of my life. If someone says their CS degree was easy they went to Purdue Global or some shit
>>
>>96082533
I would take the hug
>>
>>96080371
^ this is the winner
None of you are writing code for some real time missile command shit that needs to be the fastest and most efficient, so readibilty > efficiency
>>
.loop
...
goto loop
>>
>>96080451
>God decides to fuck with you and makes 1 not equal to 1
Code not immune to divine intervention, please amend
>>
>>96080290
loop: {
cum();
goto loop;
}
>>
>>96087858
Because that's what loops compile down to
>>
>>96087858
Sometimes the condition needs to be in the middle of the loop

while (true) {
bool end = stuff();
if (end) break;
other_stuff();
>>
>>96089565
}
>>
int main(void) {
for(int i = 50; true; i*=2) {
//...
}
}
}
>>
For me it's
while (0) {
/* do stuff */
}
>>
>>96089490
Fortunately he's not checking if 1 is 1.
Unfortunately 1 isn't an lvalue.
>>
>>96080627
wtf i love for (;;) now
>>
>he needs a keyword to do iteration
>>
>>96082533
what is wrong with this girl's hairline
>>
>>96090063
how would you do iteration without a keyword
>>
>>96091202
Recursion. It's a chad thing, you wouldn't understand. See >>96081068
>>
File: meow.gif (1.44 MB, 256x172)
1.44 MB
1.44 MB GIF
>>96080290
goto
>>
>>96091297
no i know recursion but defining a function requires a keyword
>>
File: SEI_158411039.jpg (142 KB, 1200x799)
142 KB
142 KB JPG
>>96080290
for (int i = 0; i < MAX_ITERATIONS; i++) {
// ...
}
>>
File: 1695122510057.jpg (87 KB, 736x981)
87 KB
87 KB JPG
gomming through
for {
// ...
}
>>
>>96082982
Optimizing compilers aren't always as good as you imagine them to be
>>
>>96092038
Show me an optimizing compiler that can't do this
>>
>>96083410
The loop would never end
>>
File: 1546829452471.jpg (1.27 MB, 806x5140)
1.27 MB
1.27 MB JPG
>>96081259
>>
>>96092034
that GO rat can eat my dick cheese
>>
>>96081118
Why did that get so many upvotes?
>>
>>96080451
That would just throw an error. How the fuck would you assign the value of 1 to 1? "=" is not a comparison.
>>
>>96092321
i think its a bait anon
>>
>>96080290
For me, it's Control.Monad.forever
>>
>>96092321
"=" is of course comparison. Has been for thousands of years. Assignment is ":=".
>>
>>96080290
for (;;)
because only retard morons use the other.
>>
>>96092261
I hate tranime but even I can tell this image was made with the driving force being 100% butthurt stop being cringe
>>
>>96092869
while (0-0)
>>
>>96080290
"for(;;)" because it's simpler. It's a loop that continues another iteration without checking anything. "while(1)" has to evaluate "1" to see if it's true each time.
>>
Using a for loops makes no sense for this use case. It doesn't matter what they look like, in this use case you simply have to use a while loop.
>>
>>96093063
retard
>>
>>96092261
TL;DR
Still an anime website.
>>
>>96080290

I have never found a need to use a FOR loop anywhere

Just use FOREACH loop in conjunction with INDEXER counter or an ORDINAL counter or ZEROTH counter that begin from -1

I have also never found the need to use WHILE loop, I usually just use a DO WHILE loop for that purpose and CONTINUE until BREAK with again, either an INDEXER counter ORDINAL counter or an ZEROTH counter, again starting from -1 and getting iterated by one in the beginning

I only ever saw the WHILE loop being used in C# SOCKET PROGRAMMING to await DATA BEING AVAIABLABLE boolean with an interactive getter mechanism I suppose, again I suppose, it could be the case the the getter mechanism was not interactive at all and the person just waited for a something that will always true

As for the FOR loop I only found one use case for it, when working with text files in particular

The FOR loop has its own syntax culture and it introduces variable names such as

I, J, K, L, M, N, O, X or O, P

CI, CJ

Which are very useful for keeping track of things such as

PHYSICAL_OFFSET
CHARACTER AT PHYSICAL OFFSET
VIRTUAL LINE NUMBER
VIRTUAL OFFSET SINCE THE LINE NUMBER

Apart from that the FOR loop is pretty much replaceable by a simply SET ITERATOR like the FOREACH loop
>>
#define niggers true
while(niggers) {}
>>
File: 4chan-anime.png (577 KB, 800x2810)
577 KB
577 KB PNG
>>96092261
Anime website.
>>
File: 1687089469535061.jpg (429 KB, 1200x1200)
429 KB
429 KB JPG
Char dicks[1] = "\xEB\xFE";
Plus
WriteProcessMemory
Simple as
>>
>>96092261
based

>>96097152
>>96093720
not an argument
>>
File: smug-rika-think.jpg (21 KB, 479x479)
21 KB
21 KB JPG
>>96099153
>shitty discord-tier meme picture
>based
>elaborate picture that thoroughly explains the topic
>not an argument
Feels bad having a short attention span, right?
>>
File: 0n0brc.png (469 KB, 1920x1080)
469 KB
469 KB PNG
Both compile to the same assembly, so while for readability
>>
>>96099339
baste
Out of curiosity, does [[noreturn]] do anything at all in such a function?
>>
>>96080290
while true; do true; done
>>
>>96099213
>elaborate
I guess to a weebshitter anything is complicated
>>
>>96087858
It's extremely common and useful
>>
>>96080290
what the fuck, why would you use this?
>>
do
...
end do
>>
>>96102549
Or even
do concurrent
...
end do

Simple as
>>
File: 1690252092328079.jpg (20 KB, 500x500)
20 KB
20 KB JPG
>>96092261
Anime website
>>
>>96081259
kys tranny
>>
>>96097152
>some esl faggot actually took the time to type this up
Embarrassing. I hope he killed himself.
>>
>>96080290
for (;;) because it has no condition (which is what you want)
>>
File: 1669173011353255.jpg (473 KB, 1550x2048)
473 KB
473 KB JPG
>>96080290
I just started a computer science course at a community college and my teacher failed my first assignment because I used
 while (1) 
and he said I should never under any circumstances do this and that I would never see it in any actual production code.
Should I just drop out now and self-learn or is he actually right?
>>
#include <iostream>
#include <cmath>

using namespace std;

auto main() -> int {
while (INFINITY) {
cout << "niggers" << endl;
}
return 0;
}
>>
>>96080290
consider indefinitely {

}
>>
>>96082151
>why stop there?
The Power of Jesus Comma... oh wait? Sorry.
The Power of Laziness Commands Thee!
>>
>>96103161
>college
ROFLMAO
>>
>>96102824
>>96097152
>>96093720
Frog website since 2014.
>>
>>96103161
He's an idiot, like most academics. Programs you write when you are just starting are not going to resemble real projects.
Follow his instructions *exactly*. If he fails you anyway, go snitch on him.
>>
While(true)
{
}
>>
>>96103161
https://github.com/search?q=repo%3Atorvalds%2Flinux+%22while+%281%29%22&type=code&p=1
>>
>>96080648
yourself = 'retard'
print(f'go fuck {yourself}')
>>
>>96080362
For what runtime?
>>
>>96080290
for(;;) takes up less one less byte in source code so I use that instead.
>>
>>96103161
he's true doe
>>
>>96105660
pyCHAD
>>
>>96092261
>>96097152
why must this discussion occur on a daily basis? if a picture of an anime girl doesn't sit with you well fuck off
>>
>>96105587
>lincuck troonvalds
>>
File: anime website.png (8 KB, 381x88)
8 KB
8 KB PNG
>>96092261
>>
>>96080290
For me it's
for(unsigned int i=10;i>=0;i--)
>>
>>96088006
Fucking BASED. I kneel
>>
>>96092295
because it's funneh
>>
File: 1687378542888365.jpg (53 KB, 692x488)
53 KB
53 KB JPG
>>96103168
>
auto main() -> int
>>
repeat(Int.MAX_VALUE) {

}


>b-but its not infinite
Infinity is a spook
>>
>>96111785
you're a spook
>>
File: clueless-aware.gif (96 KB, 220x220)
96 KB
96 KB GIF
>>96111802
>>
>>96103161
Your teacher is retarded.
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
char cwd[MAX_OSPATH];
int startTime, endTime;
if ( hPrevInstance ) {
return 0;
}
g_wv.hInstance = hInstance;
Q_strncpyz( sys_cmdline, lpCmdLine, sizeof( sys_cmdline ) );
Sys_CreateConsole();
SetErrorMode( SEM_FAILCRITICALERRORS );
Sys_Milliseconds();
Sys_InitStreamThread();
Com_Init( sys_cmdline );
NET_Init();
_getcwd (cwd, sizeof(cwd));
Com_Printf("Working directory: %s\n", cwd);
if ( !com_dedicated->integer && !com_viewlog->integer ) {
Sys_ShowConsole( 0, qfalse );
}
while( 1 ) {
if ( g_wv.isMinimized || ( com_dedicated && com_dedicated->integer ) ) {
Sleep( 5 );
}
startTime = Sys_Milliseconds();
IN_Frame();
Com_Frame();
endTime = Sys_Milliseconds();
totalMsec += endTime - startTime;
countMsec++;
}
}

This is the literal main function of Quake III.
>>
>>96105587
>Sign in to search code on GitHubBefore you can access our code search functionality please sign in or create a free account.
HAHAHAHAHAHAHAHA
do microsoft bootlickers really?
>>
>>96080290
Languages with forever are the best
(System verilog you fucking neets)
>>
>>96105587
tabwidth = 8 lmao
>>
>>96080362
>>96089093
You absolute fucking nocoder LARPers. Literally every compiler in existence will compile them to the exact same code, it's purely a stylistic preference with zero consequences on the actual behavior of the program.
>>
>>96103161
I hate university education so much it's unreal.
>>
>>96111639
Get in with the times grandpa.
That how C++ is done nowadays, nothing you can do about it.
>>
For me, it's
fix $ \go -> _
>>
>>96113913
Doing C++ in the first place is not a reasonable decision.
>>
File: 1655248143509.png (1016 KB, 1920x1080)
1016 KB
1016 KB PNG
>>96105466
>>
>>96103168
>>96111639
What's even the difference between
auto main() -> int

and
int main()

?
>>
>>96114442
C++ bandwagoning retardation.
>>
File: le_auto.png (56 KB, 1062x422)
56 KB
56 KB PNG
>>96114442
I don't see any.
>>
>>96114442
sepples like using auto for types but if you use them for function return types you cant see the return type from the signature
so they added type hints so now they can use auto and see the return type from the signature

so basically they created a problem and then stapled more shit onto their language to solve the problem that didn't exist in the first place
>>
>>96113793
>Literally every compiler in existence will compile them to the exact same code
Not in C# debug mode you big huge fucking nigger.
>literally
No, not literally. Dumb fucking 30 IQ nigger monkey go fucking kill yourself and do humanity a favor you dumb fucking faggot. Kill everyone related to you, you're all a fucking blight on the gene pool.
>>
File: bale-jim.jpg (111 KB, 838x480)
111 KB
111 KB JPG
>>96092555
based pascalbro
>>
>>96087968
C doesn't even support regexp.
>>
>>96115206
>Not in C# debug mode you big huge fucking nigger.
shit, irrelevant language
>>
>>96115946
>this does not agree with the thing that I said, therefore it is irrelevant
gottem
>>
>>96089565
while( !stuff() ) {}

I guess every loop can be re-written without continue and break
>>
>>96094127
for cniles,
do {} while( (it = it->next) );
>>
>>96102549
>>96102630
what language
>>
>>96116065
>>shit monkey nigger
>somehow in the right
ahah
>>
Complaining of the syntaxis instead of learning why a for block does the same as a while loop but tought different. For loops are for collections and while loops are for routines that would change the status or the boolean condition.

Codemonkey attribute does not exists by luck.
>>
>>96115206
Do your debug builds need this micro-optimization?
>>
>>96117389
No, but it's easier to write, easier to read, and never slower so I don't see a need to use the alternative.
>>
File: pajeet-tier-code.jpg (94 KB, 594x768)
94 KB
94 KB JPG
>>96080648
>>
>>96115131
It's not a type hint, faggotron, this isn't Python.
The point of trailing return types is to allow return types that depend on the type of auto templated inputs.
>>
>>96080290
while (x --> 0) {
...
}
>>
>>96080290
Use goto like real men do.
>>
void loop(){
writeln("nigger");
loop();
}
>>
>>96115131
>so basically they created a problem and then stapled more shit onto their language to solve the problem that didn't exist in the first place
This sums up C++ as a whole.
>>
>>96115206
If you compile in debug mode, you most definitely don't care about performance, you absolute fucking moron.
>c#
Lol.
>>
>>96119978
in C and C++ that's tail recursion, optimized to a simple loop
in C# that's stack overflow at runtime due to too many nested recursion calls
>>
>>96114442
The prior exists for niche cases where the return type is based on some aspect of a parameter. Retards then began to abuse it.
>>
>>96080290
while (TruePredicateSingleton.instance().value())

please do the needful sir
>>
>>96122471
based
although singletons are passe
use a factory:
while (BooleanFactory::instance()->create(Boolean::True).value())
>>
>>96080392
( ; -;)
>>
File: presentation.png (6 KB, 639x399)
6 KB
6 KB PNG
>>96115893
I'm having flashbacks. An elegant language, for a more civilized age.
>>
>>96122471
void loop(){
loop();
// do the needful here...
}
>>
>>96122585
yes, that's some fine sir engineering
>PR approved
>>
>>96081155
Based!
>>
>>96122126
This is a feature, not a bug. If a language doesn't allow TCO, it's niggerlicious and should be avoided
>>
I got taught both are bad and not to use either
>>
File: QzW6FdwweNPm.png (336 KB, 1000x1000)
336 KB
336 KB PNG
>>96092261
>>96097152
Samebot
>>
>>96080337
fpbp
>>
>>96080967
gigabased
>>
why do you even need loops
>>
>>96080290
They do the same thing. What you should be focusing on is finding a job. A great place to start looking for employment is Indeed. You won't get your dream job, but it'll get you started. It's that first job that's always the worst, after that, it gets better.
>>
>>96081600
yes.
>>
File: Soyak_anime.jpg (26 KB, 360x358)
26 KB
26 KB JPG
>>96107801
>if a picture of an anime girl doesn't sit with you well fuck off
Hmmm...... How about no?
>>
>>96102852

Kill yourself tranny faggot



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.