• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 11:09
CEST 17:09
KST 00:09
  • 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
[ASL21] Ro16 Preview Pt1: Fresh Flow6[ASL21] Ro24 Preview Pt2: News Flash10[ASL21] Ro24 Preview Pt1: New Chaos0Team Liquid Map Contest #22 - Presented by Monster Energy21ByuL: The Forgotten Master of ZvT30
Community News
MaNa leaves Team Liquid14$5,000 WardiTV TLMC tournament - Presented by Monster Energy5GSL CK: More events planned pending crowdfunding7Weekly Cups (May 30-Apr 5): herO, Clem, SHIN win0[BSL22] RO32 Group Stage5
StarCraft 2
General
Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool MaNa leaves Team Liquid Team Liquid Map Contest #22 - Presented by Monster Energy Quebec Clan still alive ? BGE Stara Zagora 2026 cancelled
Tourneys
Sparkling Tuna Cup - Weekly Open Tournament $5,000 WardiTV TLMC tournament - Presented by Monster Energy RSL Revival: Season 5 - Qualifiers and Main Event GSL CK: More events planned pending crowdfunding Sea Duckling Open (Global, Bronze-Diamond)
Strategy
Custom Maps
[D]RTS in all its shapes and glory <3 [A] Nemrods 1/4 players [M] (2) Frigid Storage
External Content
Mutation # 521 Memorable Boss The PondCast: SC2 News & Results Mutation # 520 Moving Fees Mutation # 519 Inner Power
Brood War
General
[ASL21] Ro16 Preview Pt1: Fresh Flow Leta's ASL Ro24 Review The Korean Terminology Thread ASL21 General Discussion BGH Auto Balance -> http://bghmmr.eu/
Tourneys
Escore Tournament StarCraft Season 2 [ASL21] Ro16 Group A [Megathread] Daily Proleagues [ASL21] Ro24 Group F
Strategy
Any training maps people recommend? Fighting Spirit mining rates Muta micro map competition What's the deal with APM & what's its true value
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread Battle Aces/David Kim RTS Megathread General RTS Discussion Thread Starcraft Tabletop Miniature Game
Dota 2
The Story of Wings Gaming Official 'what is Dota anymore' discussion
League of Legends
G2 just beat GenG in First stand
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 Canadian Politics Mega-thread Russo-Ukrainian War Thread European Politico-economics QA Mega-thread The China Politics Thread
Fan Clubs
The IdrA Fan Club
Media & Entertainment
[Manga] One Piece [Req][Books] Good Fantasy/SciFi books Movie Discussion!
Sports
2024 - 2026 Football Thread Formula 1 Discussion Cricket [SPORT] Tokyo Olympics 2021 Thread
World Cup 2022
Tech Support
[G] How to Block Livestream Ads
TL Community
The Automated Ban List
Blogs
lurker extra damage testi…
StaticNine
How Streamers Inspire Gamers…
TrAiDoS
Broowar part 2
qwaykee
Funny Nicknames
LUCKY_NOOB
Iranian anarchists: organize…
XenOsky
ASL S21 English Commentary…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1842 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 51m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
LamboSC2 290
Hui .286
Lowko281
ProTech127
StarCraft: Brood War
Sea 12986
Calm 7234
Bisu 3943
Horang2 2124
Jaedong 1600
Mini 611
EffOrt 522
BeSt 464
Stork 440
firebathero 397
[ Show more ]
Larva 242
Soulkey 167
Hyun 156
Zeus 148
Rush 135
actioN 133
Pusan 110
ggaemo 68
Dewaltoss 66
[sc1f]eonzerg 63
ToSsGirL 50
Mind 50
Killer 47
zelot 37
Barracks 29
Nal_rA 27
Rock 20
Movie 17
Terrorterran 15
Hm[arnc] 15
GoRush 15
IntoTheRainbow 11
SilentControl 11
Bale 10
Sexy 7
Dota 2
qojqva1945
syndereN279
420jenkins184
League of Legends
Reynor20
Counter-Strike
fl0m4522
olofmeister4293
Other Games
hiko953
B2W.Neo947
XBOCT340
crisheroes299
Pyrionflax173
KnowMe120
RotterdaM91
QueenE85
ArmadaUGS58
Mew2King36
Trikslyr20
Organizations
Other Games
WardiTV721
BasetradeTV497
Counter-Strike
PGL246
StarCraft: Brood War
Kim Chul Min (afreeca) 17
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 17 non-featured ]
StarCraft 2
• StrangeGG 67
• Shameless 2
• IndyKCrew
• Migwel
• AfreecaTV YouTube
• sooper7s
• intothetv
• Kozan
• LaughNgamezSOOP
StarCraft: Brood War
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• Noizen47
League of Legends
• Nemesis2080
• TFBlade1396
• Jankos659
Other Games
• Shiphtur27
Upcoming Events
Monday Night Weeklies
51m
OSC
8h 51m
Afreeca Starleague
18h 51m
Snow vs PianO
hero vs Rain
WardiTV Map Contest Tou…
18h 51m
GSL
20h 51m
PiGosaur Cup
1d 8h
CranKy Ducklings
1d 17h
Kung Fu Cup
1d 20h
Replay Cast
2 days
The PondCast
2 days
[ Show More ]
WardiTV Map Contest Tou…
2 days
Replay Cast
3 days
Escore
3 days
WardiTV Map Contest Tou…
3 days
Korean StarCraft League
4 days
CranKy Ducklings
4 days
WardiTV Map Contest Tou…
4 days
IPSL
5 days
WolFix vs nOmaD
dxtr13 vs Razz
BSL
5 days
Sparkling Tuna Cup
5 days
WardiTV Map Contest Tou…
5 days
Ladder Legends
5 days
BSL
6 days
IPSL
6 days
JDConan vs TBD
Aegong vs rasowy
Replay Cast
6 days
Replay Cast
6 days
Wardi Open
6 days
Afreeca Starleague
6 days
Bisu vs Ample
Jaedong vs Flash
Liquipedia Results

Completed

Escore Tournament S2: W2
RSL Revival: Season 4
NationLESS Cup

Ongoing

BSL Season 22
ASL Season 21
CSL 2026 SPRING (S20)
IPSL Spring 2026
StarCraft2 Community Team League 2026 Spring
Nations Cup 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026
IEM Kraków 2026

Upcoming

Escore Tournament S2: W3
Acropolis #4
BSL 22 Non-Korean Championship
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
RSL Revival: Season 5
WardiTV TLMC #16
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
CCT Season 3 Global Finals
IEM Rio 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.