• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 19:25
CEST 01:25
KST 08:25
  • 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
Serral wins HomeStory Cup 2914Serral wins Maestros of the Game 243ByuL, and the Limitations of Standard Play3Team Liquid Map Contest #22: Results and Winners7Code S Season 2 (2026): RO4 and Finals Preview12
Community News
Balance hotfix patch 5.0.16b (July 16)54Reynor: GSL Loss Wasn't About Preparation Format16[IPSL] Spring 2026 Grand Finals - This Weekend!6Weekly Cups (July 6 - 12): Protoss strike back12BSL Season 22 Full Overview & Conclusion8
StarCraft 2
General
Balance hotfix patch 5.0.16b (July 16) [D] Wireframe Casting Removed Clem: "I don't have that much hope in Blizzard" Reynor: GSL Loss Wasn't About Preparation Format Is the larve respawn broken?
Tourneys
Master Swan Open (Global Bronze-Master 2) WardiTV Summer Cup 2026 GSL CK #5 Race War RSL Revival: Season 6 - Qualifiers and Main Event HomeStory Cup 29
Strategy
[G] Having the right mentality to improve
Custom Maps
New Map Maker - Looking for Advice - Love or Hate Work In Progress Melee Maps [D]RTS in all its shapes and glory <3
External Content
The PondCast: SC2 News & Results Mutation # 534 Burning Evacuation Mutation # 533 Die Together Mutation # 532 Nuclear Family
Brood War
General
BW General Discussion ASL22 General Discussion NaDa’s Body Followup Pros Debate: Zerg Unfairly Nerfed? (ASL S22 map) Etiquete rules in Asl?
Tourneys
[Megathread] Daily Proleagues [IPSL] Spring 2026 Grand Finals - This Weekend! Escore Tournament - Season 3 Small VOD Thread 2.0
Strategy
Fighting Spirit mining rates Simple Questions, Simple Answers Creating a full chart of Zerg builds Relatively freeroll strategies
Other Games
General Games
Nintendo Switch Thread Path of Exile General RTS Discussion Thread Beyond All Reason Stormgate/Frost Giant Megathread
Dota 2
Looking for a Dota Mentor Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug
TL Mafia
TL Mafia Power Rank NeO.D_StephenKing vs This Guy From 1 Million Dance TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread The Games Industry And ATVI UK Politics Mega-thread YouTube Thread
Fan Clubs
The IdrA Fan Club The HerO Fan Club!
Media & Entertainment
Anime Discussion Thread Movie Discussion! [Req][Books] Good Fantasy/SciFi books Series you have seen recently...
Sports
2024 - 2026 Football Thread MLB/Baseball 2023 McBoner: A hockey love story Tennis[sport] Formula 1 Discussion
World Cup 2022
Tech Support
Simple Questions Simple Answers FPS when play League Of Legend on laptop How to clean a TTe Thermaltake keyboard?
TL Community
Northern Ireland Global Starcraft The Automated Ban List
Blogs
ASL S22 English Commentary…
namkraft
Poker (part 2)
Nebuchad
The Experiences We Want and …
TrAiDoS
An Exploration of th…
waywardstrategy
ramps on octagon
StaticNine
Funny Nicknames
LUCKY_NOOB
Evil Gacha Games and the…
ffswowsucks
Customize Sidebar...

Website Feedback

Closed Threads



Active: 8021 users

The Big Programming Thread - Page 837

Forum Index > General Forum
Post a Reply
Prev 1 835 836 837 838 839 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.
Mataru
Profile Joined June 2010
Norway356 Posts
February 07 2017 22:55 GMT
#16721
Correct. I like to visualize it as a tree where at the top level you have your numbers, each having five branches, one for each letter, which again have six branches, one for each color. There you have every possible combination: five times six branches for each number, meaning 4 * 5 * 6.
Proud citizen of ESPORTS
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2017-02-07 23:51:43
February 07 2017 23:50 GMT
#16722
Ah, discrete math from university. Mostly good memories. I don't like traditional math from school that much, but when I started studying discrete math at university, it really changed my opinion about doing math. Maybe because it involves a lot of real life problems, so you can more easily see why it could be useful.
dsyxelic
Profile Joined May 2010
United States1417 Posts
February 08 2017 00:40 GMT
#16723
On February 08 2017 06:36 Acrofales wrote:
If you don't have a server, I don't think there's much point to logging in at all, but in that case I can think of 2 ways of doing this:

1) A static database that you ship with the app, in which there are predefined users (some of which are flagged as admin), and within the app some functionality is locked (invisible) if the admin flag is off.

2) Two different apps, one for regular and one for admin users.

Regarding your second question: yes. You can either lock the access (in other words, the button to access the admin stuff is simply not there for regular users), lock the functionality (the users can see the admin functionality, but it doesn't do anything) or both. The most secure option is both, the easiest to implement is just to lock access.


ah thank you this was very helpful. will probably go with the static database + locking access to regular users.

yeah we realized how wildly impractical this app was but the whole project is graded on the process of development and simply for learning the development process so apparently it's ok even if the app is stupidly impractical.

will give it a go this weekend or so and hopefully I get some sort of functionality that I want
TL/SKT
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2017-02-08 00:58:21
February 08 2017 00:54 GMT
#16724
if i have a function


int whatever() {
while(1) {
//do some stuff
if(some condition is met) {
return (some int);
}
}
}


is this oversimplified example an easy way to create a loop in a function that needs to meet some criteria before stopping?
since this will just loop and then when it meets the criteria you can just return whatever it is you want to return ?

or are loops typically done this way?



int whatever() {
while(condition is not met) {
//do stuff
}

return(some int);

}



I guess this is a dumb question. It probably just depends on what's better for what you are trying to do. But really I am trying to make sure that nothing breaks in the first one.
Blitzkrieg0
Profile Blog Joined August 2010
United States13132 Posts
February 08 2017 00:56 GMT
#16725
break;


Would be the statement you're looking for I think.
I'll always be your shadow and veil your eyes from states of ain soph aur.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2017-02-08 00:59:13
February 08 2017 00:57 GMT
#16726
On February 08 2017 09:56 Blitzkrieg0 wrote:
break;


Would be the statement you're looking for I think.


Return works as well, though it's also missing a return at the end of the function.


On February 08 2017 09:40 dsyxelic wrote:
Show nested quote +
On February 08 2017 06:36 Acrofales wrote:
If you don't have a server, I don't think there's much point to logging in at all, but in that case I can think of 2 ways of doing this:

1) A static database that you ship with the app, in which there are predefined users (some of which are flagged as admin), and within the app some functionality is locked (invisible) if the admin flag is off.

2) Two different apps, one for regular and one for admin users.

Regarding your second question: yes. You can either lock the access (in other words, the button to access the admin stuff is simply not there for regular users), lock the functionality (the users can see the admin functionality, but it doesn't do anything) or both. The most secure option is both, the easiest to implement is just to lock access.


ah thank you this was very helpful. will probably go with the static database + locking access to regular users.

yeah we realized how wildly impractical this app was but the whole project is graded on the process of development and simply for learning the development process so apparently it's ok even if the app is stupidly impractical.

will give it a go this weekend or so and hopefully I get some sort of functionality that I want


Yeah I don't really understand why there is an admin function if it doesn't sync to an server, but if it's just for practice, sure. However there's a potential problem with implementing things in a way that you wouldn't do in a real app, which makes programming decisions strange to debate about. If you're just whitelisting the admin usernames and locally registering the user then any one can become an admin if they figure out the admin usernames. But it's not like being an admin would mean anything.
There is no one like you in the universe.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
February 08 2017 00:59 GMT
#16727
On February 08 2017 09:56 Blitzkrieg0 wrote:
break;


Would be the statement you're looking for I think.


so are you saying that instead of just returning the value from within the loop, first break (to take me out of the loop?) and then return the value?

Is there a reason to not doing the former?
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2017-02-08 01:06:26
February 08 2017 01:04 GMT
#16728
On February 08 2017 09:59 travis wrote:
Show nested quote +
On February 08 2017 09:56 Blitzkrieg0 wrote:
break;


Would be the statement you're looking for I think.


so are you saying that instead of just returning the value from within the loop, first break (to take me out of the loop?) and then return the value?

Is there a reason to not doing the former?


It depends on your coding standards and the control flow.

+ Show Spoiler +


int fun() {
while (1) {
if (cond) {
break;
}
}
return getCondValue();
}



int fun() {
int result = 0;
while (1) {
if (cond) {
result = getValue(cond);
break;
}
}
return result;
}



int fun() {
while (1) {
if (cond) {
return getValue(cond);
}
}
return 0; // never gets here
}



int fun() {
while (1) {
if (cond) {
return getCondValue();
}
}
return 0; // never gets here
}



etc etc... all equivalent, whatever fits your scenario, whatever code you like more.
There is no one like you in the universe.
Blitzkrieg0
Profile Blog Joined August 2010
United States13132 Posts
Last Edited: 2017-02-08 01:15:33
February 08 2017 01:05 GMT
#16729
On February 08 2017 09:59 travis wrote:
Show nested quote +
On February 08 2017 09:56 Blitzkrieg0 wrote:
break;


Would be the statement you're looking for I think.


so are you saying that instead of just returning the value from within the loop, first break (to take me out of the loop?) and then return the value?

Is there a reason to not doing the former?


I'm saying don't make a new function that is just a loop so you can terminate it with a return value. It's not wrong, but I don't see why you'd want to write code that way.

If this is just a small part of a larger example, I would suggest using a break statement if this function has more than one possible return. When you're debugging things it is advantageous to have exactly one place that the function returns.
+ Show Spoiler [example code] +

int fun() {
int result = 0;
while (1) {
if (cond) {
result = getValue(cond);
break;
} else if (cond2) {
result = getValue(cond2);
break;
}
}
return result;
}

int fun() {
int result = 0;
while (1) {
if (cond) {
return getValue(cond);
} else if (cond2) {
return getValue(cond2);
}
}
return error;
}


Simple example, but when you're debugging something and the logic becomes more complicated I find it easier to debug with the former than the latter.
I'll always be your shadow and veil your eyes from states of ain soph aur.
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2017-02-08 02:07:30
February 08 2017 01:53 GMT
#16730
On February 08 2017 10:05 Blitzkrieg0 wrote:
Show nested quote +
On February 08 2017 09:59 travis wrote:
On February 08 2017 09:56 Blitzkrieg0 wrote:
break;


Would be the statement you're looking for I think.


so are you saying that instead of just returning the value from within the loop, first break (to take me out of the loop?) and then return the value?

Is there a reason to not doing the former?


I'm saying don't make a new function that is just a loop so you can terminate it with a return value. It's not wrong, but I don't see why you'd want to write code that way.

If this is just a small part of a larger example, I would suggest using a break statement if this function has more than one possible return. When you're debugging things it is advantageous to have exactly one place that the function returns.
+ Show Spoiler [example code] +

int fun() {
int result = 0;
while (1) {
if (cond) {
result = getValue(cond);
break;
} else if (cond2) {
result = getValue(cond2);
break;
}
}
return result;
}

int fun() {
int result = 0;
while (1) {
if (cond) {
return getValue(cond);
} else if (cond2) {
return getValue(cond2);
}
}
return error;
}


Simple example, but when you're debugging something and the logic becomes more complicated I find it easier to debug with the former than the latter.


First, you shouldn't use while (1). That's awful. You should #include <stdbool.h> and use while (true). Secondly, you never return error. There's no condition to reach that code in your example. Finally, if you really want to do this properly, you'd usually use a thread with a callback function instead of blocking main thread like that (I assume you're doing that).

I also see no problem with this example:


while (true)
{
if (condition)
return getValue(condition);

<brief sleep so you don't waste CPU>
}


Hard to debug? If you find this hard to debug, you need to change your IDE or learn how to do it. It's super easy to debug in IDE like Visual Studio.
Blitzkrieg0
Profile Blog Joined August 2010
United States13132 Posts
February 08 2017 02:29 GMT
#16731
On February 08 2017 10:53 Shield wrote:
First, you shouldn't use while (1). That's awful. You should #include <stdbool.h> and use while (true). Secondly, you never return error. There's no condition to reach that code in your example. Finally, if you really want to do this properly, you'd usually use a thread with a callback function instead of blocking main thread like that (I assume you're doing that).


You never return error is precisely why it's an error. I prefer self documenting code instead of adding a comment that says "never gets here" like Blisse, for example ERR_UNREACHABLE.

Travis is just learning C so lets assume his application isn't multi-threaded.
I'll always be your shadow and veil your eyes from states of ain soph aur.
Neshapotamus
Profile Blog Joined May 2006
United States163 Posts
February 08 2017 03:45 GMT
#16732
After seeing travis post his simple question.

I have seen people write this code in every which way (code at bottom)

I listed several of them at the bottom.

Anyone have any preference to which version they write?

More recently, I prefer to write "fun1" way as this is the easiest to reason about meaning it maps directly into math. You also get other benefits as its easier to parallelize. However, you need a TCO language to execute the statement.

The second most intuitive is fun2.

Anyone who writes fun5, I just avoid...



void fun1(){

void fun(int a, int b) {
if (a > b){
return
}
else fun(a, b+1)
}

a = <init>
b = <init>
fun(a,b)
}



void fun2(){
a = <init>
for(int b = <init>; a > b; b++){
}
}

void fun3(){
a = <init>
b = <init>
while(true){
if (a > b){
break;
}
b += 1
}
}

void fun4(){
a = <init>
b = <init>
while(a > b){
b += 1
}
}

void fun5(){
start:
if (a > b){
b += 1
goto start
}
}

Hanh
Profile Joined June 2016
146 Posts
February 08 2017 04:33 GMT
#16733
Well, in this particular case I'd prefer

a = <init>
b = max(<init>, a)


because, why would you even loop?

But in the more general case, I'd go for


for (a = <init>, b = <init>; a > b; b++) ;


In order of best to worse, I'd rate 2, 4, 3, 5, 1. Btw, these functions aren't doing exactly the same thing.
Deleted User 173346
Profile Blog Joined April 2011
16169 Posts
Last Edited: 2017-02-08 05:23:44
February 08 2017 05:22 GMT
#16734
--- Nuked ---
WolfintheSheep
Profile Joined June 2011
Canada14127 Posts
Last Edited: 2017-02-08 05:33:54
February 08 2017 05:33 GMT
#16735
struct Test //creates a structure
{
char name[10]; //a 10-character array
int num1; //the first integer
int num2; //the second integer
int sum; //the result of the subtraction of num2 from num1
}
inst; //instance of the struct

...

inst.sum = &inst.num1 - &inst.num2;
printf("The result is: %d\n", &inst.sum);


So first question is, why you are using ampersands here? Which should tell you the exact answer about why this isn't working.

+ Show Spoiler +
Hint: 134615508 is a memory address.
Average means I'm better than half of you.
Deleted User 173346
Profile Blog Joined April 2011
16169 Posts
Last Edited: 2017-02-08 05:48:57
February 08 2017 05:36 GMT
#16736
--- Nuked ---
Neshapotamus
Profile Blog Joined May 2006
United States163 Posts
February 08 2017 06:21 GMT
#16737
On February 08 2017 13:33 Hanh wrote:
Well, in this particular case I'd prefer

a = <init>
b = max(<init>, a)


because, why would you even loop?

But in the more general case, I'd go for


for (a = <init>, b = <init>; a > b; b++) ;


In order of best to worse, I'd rate 2, 4, 3, 5, 1. Btw, these functions aren't doing exactly the same thing.


I should have added a little more in the template. I was just making a point that you can loop in multiple ways. From a compiler perspective, yes, they aren't doing the same thing. From an abstraction perspective, they are. Unless you can tell me otherwise?
Hanh
Profile Joined June 2016
146 Posts
February 08 2017 06:38 GMT
#16738
In fun1 (assuming you could nest functions in C), arguments are passed by value so at the end, a & b aren't changed. In 2, 3, 4, 5 sometimes a > b is the condition for breaking out of the loop, and sometimes it is the condition for continuing looping.

Blisse
Profile Blog Joined July 2010
Canada3710 Posts
February 08 2017 07:13 GMT
#16739
On February 08 2017 12:45 Neshapotamus wrote:
After seeing travis post his simple question.

I have seen people write this code in every which way (code at bottom)

I listed several of them at the bottom.

Anyone have any preference to which version they write?

More recently, I prefer to write "fun1" way as this is the easiest to reason about meaning it maps directly into math. You also get other benefits as its easier to parallelize. However, you need a TCO language to execute the statement.

The second most intuitive is fun2.

Anyone who writes fun5, I just avoid...
+ Show Spoiler +



void fun1(){

void fun(int a, int b) {
if (a > b){
return
}
else fun(a, b+1)
}

a = <init>
b = <init>
fun(a,b)
}



void fun2(){
a = <init>
for(int b = <init>; a > b; b++){
}
}

void fun3(){
a = <init>
b = <init>
while(true){
if (a > b){
break;
}
b += 1
}
}

void fun4(){
a = <init>
b = <init>
while(a > b){
b += 1
}
}

void fun5(){
start:
if (a > b){
b += 1
goto start
}
}



fun2 is the only one I would ever conceivably write. The rest are complete no-gos and i'd never accept fun3-5 in a code review when there exists an equivalent form in fun2. It's my anti-while loop bias.
There is no one like you in the universe.
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
February 08 2017 07:23 GMT
#16740
On February 08 2017 11:29 Blitzkrieg0 wrote:
Show nested quote +
On February 08 2017 10:53 Shield wrote:
First, you shouldn't use while (1). That's awful. You should #include <stdbool.h> and use while (true). Secondly, you never return error. There's no condition to reach that code in your example. Finally, if you really want to do this properly, you'd usually use a thread with a callback function instead of blocking main thread like that (I assume you're doing that).


You never return error is precisely why it's an error. I prefer self documenting code instead of adding a comment that says "never gets here" like Blisse, for example ERR_UNREACHABLE.

Travis is just learning C so lets assume his application isn't multi-threaded.


Well, in that case it's nice to have assert(false).
Prev 1 835 836 837 838 839 1032 Next
Please log in or register to reply.
Live Events Refresh
Epic.LAN
13:00
Epic.LAN 48 Playoff Stage
epiclan75
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
ViBE224
PiGStarcraft11
StarCraft: Brood War
NaDa 40
Dota 2
syndereN332
LuMiX1
Counter-Strike
summit1g5025
fl0m1516
minikerr38
Super Smash Bros
hungrybox835
Mew2King307
Heroes of the Storm
Trikslyr88
Other Games
gofns12016
tarik_tv7326
Grubby3519
C9.Mang0592
XaKoH 145
Organizations
Other Games
gamesdonequick2091
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 13 non-featured ]
StarCraft 2
• Hupsaiya 118
• RyuSc2 35
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• FirePhoenix23
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Upcoming Events
RSL Revival
9h 35m
Classic vs Trap
herO vs SHIN
Sparkling Tuna Cup
10h 35m
OSC
13h 35m
IPSL
16h 35m
Bonyth vs Ret
WardiTV Weekly
1d 11h
Monday Night Weeklies
1d 16h
OSC
2 days
PiGosaur Cup
3 days
The PondCast
3 days
Replay Cast
4 days
[ Show More ]
CrankTV Team League
4 days
Replay Cast
5 days
CrankTV Team League
5 days
Korean StarCraft League
6 days
RSL Revival
6 days
Online Event
6 days
Liquipedia Results

Completed

Escore Tournament S3: W3
HSC XXIX
Eternal Conflict S2 E2

Ongoing

IPSL Spring 2026
Acropolis #4
YSL S3
CSL 2026 Summer (S21)
KCM Race Survival 2026 Season 3
Proleague 2026-07-18
RSL Revival: Season 6
CranK Gathers Season 4: BW vs SC2 Team League
SCTL 2026 Spring
Stake Ranked Episode 3
XSE Pro League 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026

Upcoming

Escore Tournament S3: W4
ASL S22 SEASON OPEN Day 2
Escore Tournament S3: W5
CSLAN 4
Blizzard Classic Cup 2026
HSC XXX
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
Light Tournament 2026
Eternal Conflict S2 Finale
Eternal Conflict S2 E3
Logitech G Connect 2026
StarSeries Fall 2026
FISSURE Playground #5
BLAST Open Fall 2026
Esports World Cup 2026
BLAST Bounty Summer 2026
BLAST Bounty Summer Qual
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.