• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 21:42
CEST 03:42
KST 10:42
  • 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
TL.net Map Contest #22 - Voting & Ladder Map Selection2Code S Season 2 (2026) - RO8 Preview5[ASL21] Finals Preview: Two Legacies21Code S Season 2 (2026) - RO12 Preview2herO wins GSL Code S Season 1 (2026)7
Community News
Weekly Cups (May 25-31): Clem doubles, 2v2 circuit heads toward finale0StarCraft II 5.0.16 PTR Patch Notes may 26th137Weekly Cups (May 18-24): MaxPax wins doubles0Crank Gathers Season 4: BW vs SC2 Team League5Weekly Cups (May 11-17): Classic wins double1
StarCraft 2
General
StarCraft II 5.0.16 PTR Patch Notes may 26th The Death of Cheese: From a Professional Cheeser Oliveira Would Have Returned If EWC Continued SC2 Parody - "Somebody That I Used to Troll" On design and lattest PTR patch notes
Tourneys
Maestros of The Game 2 announcement and schedule ! Sparkling Tuna Cup - Weekly Open Tournament RSL Revival: Season 5 - Qualifiers and Main Event Crank Gathers Season 4: BW vs SC2 Team League GSL Code S Season 2 (2026)
Strategy
[G] Having the right mentality to improve
Custom Maps
[D]RTS in all its shapes and glory <3 [A] Nemrods 1/4 players
External Content
The PondCast: SC2 News & Results Mutation # 528 Infection Detected Welcome to the External Content forum Mutation # 527 Hell Train
Brood War
General
[BSL22] Non-Korean Championship from 13 to 28 June FlaShFTW vs A.Alm Grudge Match Event vespene.gg — BW replays in browser Quality of life changes in BW that you will like ? Data analysis on 70 million replays
Tourneys
[ASL21] Grand Finals [Megathread] Daily Proleagues Escore Tournament StarCraft Season 2 [BSL22] WB Final & LB Semis - Saturday 21:00 CEST
Strategy
Any training maps people recommend? Muta micro map competition [G] Hydra ZvZ: An Introduction Fighting Spirit mining rates
Other Games
General Games
Stormgate/Frost Giant Megathread Path of Exile Nintendo Switch Thread Warcraft III: The Frozen Throne ZeroSpace Megathread
Dota 2
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 Heroes of StarCraft mini-set
TL Mafia
Vanilla Mini Mafia Mafia Game Mode Feedback/Ideas TL Mafia Community Thread Five o'clock TL Mafia
Community
General
US Politics Mega-thread Dating: How's your luck? Russo-Ukrainian War Thread Trading/Investing Thread Things Aren’t Peaceful in Palestine
Fan Clubs
The herO Fan Club!
Media & Entertainment
[Manga] One Piece Anime Discussion Thread [Req][Books] Good Fantasy/SciFi books
Sports
McBoner: A hockey love story 2024 - 2026 Football Thread TeamLiquid Health and Fitness Initiative For 2023 Formula 1 Discussion
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread Facing Challenges in Mobile App Development
TL Community
The Automated Ban List
Blogs
Esportsmanship: How to NOT B…
TrAiDoS
Why RTS gamers make better f…
gosubay
ramps on octagon
StaticNine
ASL S21 English Commentary…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2948 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
PiGosaur Cup
00:00
PiGosaur #84 PTR
ZombieGrub229
CranKy Ducklings131
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
PiGStarcraft528
ZombieGrub229
RuFF_SC2 85
Nina 47
Ketroc 42
StarCraft: Brood War
Artosis 648
Shinee 31
ajuk12(nOOB) 22
NaDa 21
Dota 2
monkeys_forever546
LuMiX1
League of Legends
Doublelift4174
Counter-Strike
Coldzera 1961
Fnx 1637
taco 290
Other Games
summit1g11952
Day[9].tv964
shahzam677
C9.Mang0518
Maynarde80
ViBE49
minikerr12
Organizations
Other Games
gamesdonequick1299
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 15 non-featured ]
StarCraft 2
• CranKy Ducklings SOOP44
• davetesta17
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• masondota2729
League of Legends
• Stunt198
Other Games
• Day9tv964
Upcoming Events
The PondCast
8h 18m
Kung Fu Cup
9h 18m
uThermal 2v2 Circuit
13h 18m
Maestros of the Game
13h 48m
ByuN vs herO
Rogue vs Bunny
Replay Cast
22h 18m
Replay Cast
1d 7h
WardiTV Spring Champion…
1d 9h
OSC
1d 11h
Maestros of the Game
1d 13h
Serral vs Percival
SHIN vs ShoWTimE
Replay Cast
2 days
[ Show More ]
uThermal 2v2 Circuit
2 days
Maestros of the Game
2 days
Clem vs Lambo
Zoun vs SKillous
Replay Cast
3 days
Solar vs Classic
uThermal 2v2 Circuit
3 days
Grudge Match
3 days
FlaShFTW vs A.Alm
GSL
4 days
herO vs Rogue
Maru vs Cure
Patches Events
4 days
uThermal 2v2 Circuit
4 days
BSL
4 days
Replay Cast
5 days
Monday Night Weeklies
5 days
Sparkling Tuna Cup
6 days
Liquipedia Results

Completed

KK 2v2 League Season 1
RSL Revival: Season 5
Heroes Pulsing #1

Ongoing

BSL Season 22
IPSL Spring 2026
KCM Race Survival 2026 Season 2
Acropolis #4
CSCL: Masked Kings S4
YSL S3
SCTL 2026 Spring
WardiTV Spring 2026
Maestros of the Game 2
2026 GSL S2
Murky Cup 2026
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
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026

Upcoming

BSL 22 Non-Korean Championship
CSLAN 4
Blizzard Classic Cup 2026
Kung Fu Cup 2026 Grand Finals
CranK Gathers Season 4: BW vs SC2 Team League
HSC XXIX
uThermal 2v2 2026 Main Event
Heroes Pulsing #3
Heroes Pulsing #2
Esports World Cup 2026
BLAST Bounty Summer 2026
BLAST Bounty Summer Qual
Stake Ranked Episode 3
XSE Pro League 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.