• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 02:31
CEST 08:31
KST 15:31
  • 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
[ASL22] Ro16 Preview: Rough Waters9[ASL22] Ro24 Preview: Siren's Call8[ASL22] Ro24 Preview: Summer's End9Serral wins HomeStory Cup 2915Serral wins Maestros of the Game 244
Community News
Weekly Cups (Aug 30-Sep 7): herO thrives amid growing schism4Official StarCraft website teases new content ahead of BlizzCon?118Stellar Fest TWO the Moon (Dec 16-20)9Weekly Cups (August 24-30): Patches' balance mod takes over3New 3v3 BGH Ladder (and more) on ShieldBattery!46
StarCraft 2
General
Weekly Cups (Aug 30-Sep 7): herO thrives amid growing schism Nexon wins bid to develop StarCraft IP content, distribute Overwatch mobile game Balance hotfix patch 5.0.16b (July 16) SC4ALL: II Winner Will Earn a Spot at HSC 30! Weekly Cups (August 24-30): Patches' balance mod takes over
Tourneys
Sea Duckling Open (Global, Bronze-Diamond) 2026 GSTL Announcement Sparkling Tuna Cup - Weekly Open Tournament Stellar Fest TWO the Moon (Dec 16-20) IntoTheTV X SOOP SC2 League : Weekly & Monthly
Strategy
[G] Having the right mentality to improve
Custom Maps
Nexus Wars 2021 GUIDE [M] (2) Industrial Park
External Content
Mutation # 542 The Ascended Mutation # 541 Binary Choice The PondCast: SC2 News & Results Mutation # 540 Dodge This
Brood War
General
Official StarCraft website teases new content ahead of BlizzCon? [ASL22] Ro16 Preview: Rough Waters ASL22 General Discussion Pros React To: Calm's Big Brain Play Vs Mini New 3v3 BGH Ladder (and more) on ShieldBattery!
Tourneys
[ASL22] Ro16 Group B [Megathread] Daily Proleagues 2v2v2v2 Tournament [ASL22] Ro16 Group A
Strategy
Replay Review Process - What do you do? Simple Questions, Simple Answers Odyssey Mineral Stack Saturation Game Theory for Starcraft
Other Games
General Games
Nintendo Switch Thread EVE Corporation Diablo IV [Maplestory Hardcore] Let's Play~!! General RTS Discussion Thread
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
[TL LoL EUW IHs] Teemo shall perish TSM pausing esports and CLG Dead
Heroes of the Storm
Heroes of the Storm 2.0
Hearthstone
Deck construction bug
TL Mafia
TL Mafia Power Rank TL Mafia Community Thread NeO.D_StephenKing vs This Guy From 1 Million Dance
Community
General
US Politics Mega-thread Trading/Investing Thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread UK Politics Mega-thread
Fan Clubs
MarineLorD Fan Club The Creator Fan Club The ShoWTimE Fan Club
Media & Entertainment
Movie Discussion! Anime Discussion Thread
Sports
Football (Soccer) Thread TeamLiquid Health and Fitness Initiative For 2023 MLB/Baseball 2023
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Northern Ireland Global Starcraft
Blogs
F* the Children and Get Off …
TrAiDoS
Dreaming of BW patches (mod…
c3rberUs
Regacy Esports: The Bh…
regacyesports
LOCKPICKING NOOB
LUCKY_NOOB
Customize Sidebar...

Website Feedback

Closed Threads



Active: 7269 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
Next event in 4h 29m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
EnDerr 7
StarCraft: Brood War
Shuttle 3238
Rain 2076
BeSt 244
sSak 73
Hm[arnc] 44
Mind 38
Yoon 34
Bale 23
ZergMaN 12
Noble 7
[ Show more ]
Icarus 6
Dota 2
monkeys_forever330
League of Legends
JimRising 709
Super Smash Bros
hungrybox436
Other Games
summit1g8857
WinterStarcraft417
Happy132
ceh933
[ Show 13 non-featured ]
StarCraft 2
• Berry_CruncH329
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• Migwel
StarCraft: Brood War
• iopq 7
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• masondota21372
• lizZardDota2119
League of Legends
• Lourlo1258
Upcoming Events
Kung Fu Cup
4h 29m
Replay Cast
17h 29m
The PondCast
1d 3h
KCM Race Survival
1d 3h
Escore
2 days
IntoTheTV X SOOP
2 days
CranKy Ducklings
3 days
Sparkling Tuna Cup
4 days
Shopify Rebellion Sundays
4 days
Spirit vs Mixu
Clem vs TBD
RSL Revival
4 days
[ Show More ]
BlizzCon
4 days
Replay Cast
4 days
Afreeca Starleague
5 days
WardiTV Weekly
5 days
Afreeca Starleague
6 days
GSL
6 days
PiGosaur Cup
6 days
Liquipedia Results

Completed

Proleague 2026-09-08
PiG Sty Festival 8.0
Big Dog Cup 2026 Div 1

Ongoing

KCM Race Survival 2026 Season 3
K-JUNGMAN
ASL Season 22
Super Anchor Qualifying S3
CSL 2026 AUTUMN (S22)
Acropolis #5
Acropolis #5 - TRS
RSL Revival: Season 6
Calamity Invitational
FISSURE Playground #3
BLAST Open Fall 2026
Esports World Cup 2026
BLAST Bounty Summer 2026
BLAST Bounty Summer Qual
Stake Ranked Episode 3
XSE Pro League 2026

Upcoming

Escore Tournament S3: King of Kings
Acropolis #5 - GSA
Blizzard Classic Cup 2026
Acropolis #5 - GSB
Acropolis #5 - GSC
SC4ALL II: Brood War
HSC XXX
Stellar Fest 2: Lunar Cup
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
RSL Offline Finals
Blizzard Classic Cup 2026
Stake Ranked Episode 6
BLAST Rivals Fall 2026
IEM Beijing 2026
Stake Ranked Episode 5
PGL Masters Bucharest 2026
1win Private Club #2
Thunderpick World Champ. '26
ESL Pro League Season 24
Stake Ranked Episode 4
1win Private Club #1
Logitech G Play Connect 2026
SL StarSeries Fall 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.