i have a hard time understanding the "if let" syntax
i was reading through the book, and stumbled upon chapter 6.3: [concise control flow with if let](https://doc.rust-lang.org/book/ch06-03-if-let.html#concise-control-flow-with-if-let) 

i read the part about "if let" seven times or so, but i can still not wrap my head around why this syntax is like that.

i feel that i can probably apply the syntax to have result, but that unless i un…
i've been meaning to write a blog post on this for a while, but haven't got round to it yet, so i'll give the condensed version here :slight\_smile:

to understand why the if let syntax is the way it is, we should first look at the let syntax. in most cases, you'll see it used for simple variable dec…
if statements always check if an expression evaluates to the value of true. since you’re checking whether the value true  value true then it’ll run every time. as for the “purpose” of the if statement, it’s here to create a “block scope” within the “function scope”.

interestingly, if you remove … its kind difficult to understand in my POV but not impossible  

imagining it while reading


can you show some codes? or samples on what you want to achive? direction: a word and number arrangement machine when given an input line of word and numbers rearranges them following a particular rule in each step. the following is an illustration of input and rearrangement. input: politics 61 policy 116 partner 93 role 45 clear 27 38 point step i: role politics policy 116 partner 93 45 clear 27 38 point 61 step ii: role clear politics policy partner 93 45 27 38 point 116 61 step iii: role clear partner politics policy 93 45 38 point 27 116 61 step iv: role clear partner politics policy 93 38 point 45 27 116 61 step v: role clear partner politics point policy 93 38 45 27 116 61 step v, is the last step of the above arrangement as the intended arrangement is obtained. as per the rule followed in the given steps find out the appropriate steps for the given input. input: energy 54 78 place 23 issue 211 145 flat rent taxi 17in step iii, what is the difference between fifth element from left and second element from right? Well.



Think about what you know about lifts.



Go with the theory of 2 lifts, one you have more than 1 lift the logic is the same you just have more options.



Lifts go 1 of 2 ways. up or down.  

A lift at floor 1 told to go up, if someone rings the bell on 3 and the lift is going there or passing there on the way up and the person said "up" on 3.. then it will stop, otherwise if its not due to stop there and the person said down, it wont. The other lift will get the job, or if both are going up, then it will be the first available lift.



Your lift needs states waiting/up/down



Your logic shouldnt be that complex, so, write down in words what your logic choices are, senarios etc



Then you should be ready to code it because each time fill() is invoked it is only applying 0.047% opacity over what was previously drawn. draw() runs aprox 60 times per second … It's going to be sheer luck anyone is running that setup so try this. Break the problem down to smaller steps. If a step can't be accomplished then it's too big a step. Break it down further. its to do with the jit optimisation, the same is true if you insert conditional debug statement in the code, matlab needs to prepare to stop execution. This is indeed something of a problem. It is always difficult to jump into a new and large code-base. You should concentrate on any available overview documentation (e.g., explaining how it works or is structured), tutorials (e.g., showing how to make mods), and reference documentation (e.g., class references).


If you need to really dig into the source code of the library / application, then you need to find a relevant starting point. This could be something that is similar to what you want to do or modify. When you find a decent starting point, just look it up and try to understand what it does and how it works, and work your way out from there, by looking up related code (e.g., that is called within that code you are looking at, etc.). The "find in files" is definitely a central tool when exploring a code-base because it gives you an instant snapshot of where certain things are used and declared. For example, if you want to modify the behavior of class A, then there is a good chance that you will want to look at all the places where class A is used so that you can assess if your modified version will work or if you need to modify other things.


There is no doubt that doing this is hard and takes a lot of patience. I've done this several times with different code bases (some small ( < 50,000 LOCs ), some big ( > 1,000,000 LOCs )), and it's always a tedious process, especially if documentation is lacking (which it very often is). > 
> My question is when does this function works improperly and why?
> 
> 
> 


Technically it works improperly when you call it with an input stream or an update stream in input mode. That is, if you use fopen() with a "w" mode, or a "+" mode and you're currently in the process of reading from the stream, or stdin.


In practice, all of the above situations are okie dokie *iff* the compiler supports them (and some do, including Borland and Microsoft compilers). In terms of best practice, fflush() on an input stream is frowned upon.


However, note that calling fflush() on an output stream is both well defined and recommended for things such as forcing a user prompt to display, well...promptly. :)



> 
> Nowadays I use scanf("[^\n]") to flush input stream. Is this ok?
> 
> 
> 


Close. The correct call for scanf() to read up to a newline would be:



```
scanf("%*[^\n]");

```

This isn't complete though, because the newline will still be in the stream. You still need to extract it. One way would be to add an ignored character match in the format string:



```
scanf("%*[^\n]%*c");

```

This might not be as flexible though, if you want to do other stuff like count discarded characters. Another way would be to call getchar() after scanf():



```
scanf("%*[^\n]");
getchar();

```

Finally, there's the far more common (and faster!) method of calling getchar() in a loop. I'll even give you a function that you can call instead of having to write it ad hoc every time:



```
#include <stdio.h>

void clear_line(FILE *in)
{
    int ch;

    /* Do nothing if the stream is in an error state */
    if (ferror(in))
        return;

    /* Make sure any end-of-file  state is cleared */
    clearerr(in);

    /* Extract and discard up to a newline or end-of-file */
    do
        ch = getc(in);
    while (ch != '\n' && ch != EOF);

    /*
        Clear an end-of-file state if we stoped on EOF,
        but leave any legitimate error state for the caller
    */
    if (!ferror(in))
        clearerr(in);
}

```

Note that even this solution is incomplete when compared with what people expect from `fflush(stdin)` because it blocks for input when the stream is empty. fflush(), when flushing input streams is supported, will return without blocking on an empty stream. Unfortunately, there's no portable way to emulate that behavior, but it's fairly simple to just ensure that the stream is never empty when calling clear\_line().



> 
> fflush( std::cout );
> 
> 
> 


Yeah, that won't work. fflush() expects a pointer to FILE, not an std::ostream object. std::ostream has its own flush() member for synchronizing with the destination device.


It's also quite silly to flush cout explicitly prior to accepting input through cin because the two are tied together. As soon as you request input from cin, the tied stream (cout) is automatically flushed. Doing it yourself explicitly isn't harmful, but it *is* redundant.


It's actually a pretty nifty feature of the iostream library. Read more about it starting [here](http://www.cplusplus.com/reference/iostream/ios/tie/). Correct syntax is:



```
do
...
loop until ........
```

OR



```
while .......
....
wend
```