بایگانی دسته: وی پی ان لینوکس

Auto Added by WPeMatico

Using Break and Continue Statements When Working with Loops in Go

Introduction

Using for loops in Go allow you to automate and repeat tasks in an efficient manner.

Learning how to control the operation and flow of loops will allow for customized logic in your program. You can control your loops with the break and continue statements.

Break Statement

In Go, the break statement terminates execution of the current loop. A break is almost always paired with a conditional if statement.

Let’s look at an example that uses the break statement in a for loop:
break.gopackage main

import “fmt”

func main() {
for i := 0; i < 10; i++ {
if i == 5 {
fmt.Println(“Breaking out of loop”)
break // break here
}
fmt.Println(“The value of i is”, i)
}
fmt.Println(“Exiting program”)
}

This small program creates a for loop that will iterate while i is less than 10.

Within the for loop, there is an if statement. The if statement tests the condition of i to see if the value is less than 5. If the value of i is not equal to 5, the loop continues and prints out the value of i. If the value of i is equal to 5, the loop will execute the break statement, print that it is Breaking out of loop, and stop executing the loop. At the end of the program we print out Exiting program to signify that we have exited the loop.

When we run this code, our output will be the following:
OutputThe value of i is 0
The value of i is 1
The value of i is 2
The value of i is 3
The value of i is 4
Breaking out of loop
Exiting program

This shows that once the integer i is evaluated as equivalent to 5, the loop breaks, as the program is told to do so with the break statement.

Nested Loops

It is important to remember that the break statement will only stop the execution of the inner most loop it is called in. If you have a nested set of loops, you will need a break for each loop if desired.
nested.gopackage main

import “fmt”

func main() {
for outer := 0; outer < 5; outer++ {
if outer == 3 {
fmt.Println(“Breaking out of outer loop”)
break // break here
}
fmt.Println(“The value of outer is”, outer)
for inner := 0; inner < 5; inner++ {
if inner == 2 {
fmt.Println(“Breaking out of inner loop”)
break // break here
}
fmt.Println(“The value of inner is”, inner)
}
}
fmt.Println(“Exiting program”)
}

In this program, we have two loops. While both loops iterate 5 times, each has a conditional if statement with a break statement. The outer loop will break if the value of outer equals 3. The inner loop will break if the value of inner is 2.

If we run the program, we can see the output:
OutputThe value of outer is 0
The value of inner is 0
The value of inner is 1
Breaking out of inner loop
The value of outer is 1
The value of inner is 0
The value of inner is 1
Breaking out of inner loop
The value of outer is 2
The value of inner is 0
The value of inner is 1
Breaking out of inner loop
Breaking out of outer loop
Exiting program

Notice that each time the inner loop breaks, the outer loop does not break. This is because break will only break the inner most loop it is called from.

We have seen how using break will stop the execution of a loop. Next, let’s look at how we can continue the iteration of a loop.

Continue Statement

The continue statement is used when you want to skip the remaining portion of the loop, and return to the top of the loop and continue a new iteration.

As with the break statement, the continue statement is commonly used with a conditional if statement.

Using the same for loop program as in the preceding Break Statement section, we’ll use a continue statement rather than a break statement:
continue.gopackage main

import “fmt”

func main() {
for i := 0; i < 10; i++ {
if i == 5 {
fmt.Println(“Continuing loop”)
continue // break here
}
fmt.Println(“The value of i is”, i)
}
fmt.Println(“Exiting program”)
}

The difference in using the continue statement rather than a break statement is that our code will continue despite the disruption when the variable i is evaluated as equivalent to 5. Let’s look at our output:
OutputThe value of i is 0
The value of i is 1
The value of i is 2
The value of i is 3
The value of i is 4
Continuing loop
The value of i is 6
The value of i is 7
The value of i is 8
The value of i is 9
Exiting program

Here we see that the line The value of i is 5 never occurs in the output, but the loop continues after that point to print lines for the numbers 6-10 before leaving the loop.

You can use the continue statement to avoid deeply nested conditional code, or to optimize a loop by eliminating frequently occurring cases that you would like to reject.

The continue statement causes a program to skip certain factors that come up within a loop, but then continue through the rest of the loop.

Conclusion

The break and continue statements in Go will allow you to use for loops more effectively in your code.

خرید وی پی ان آنتی فیلترآنتی فیلتر

How To Write Conditional Statements in Go

Introduction

Conditional statements are part of every programming language. With conditional statements, we can have code that sometimes runs and at other times does not run, depending on the conditions of the program at that time.

When we fully execute each statement of a program, we are not asking the program to evaluate specific conditions. By using conditional statements, programs can determine whether certain conditions are being met and then be told what to do next.

Let’s look at some examples where we would use conditional statements:

If the student receives over 65% on her test, report that her grade passes; if not, report that her grade fails.
If he has money in his account, calculate interest; if he doesn’t, charge a penalty fee.
If they buy 10 oranges or more, calculate a discount of 5%; if they buy fewer, then don’t.

Through evaluating conditions and assigning code to run based on whether or not those conditions are met, we are writing conditional code.

This tutorial will take you through writing conditional statements in the Go programming language.

If Statements

We will start with the if statement, which will evaluate whether a statement is true or false, and run code only in the case that the statement is true.

In a plain text editor, open a file and write the following code:
grade.gopackage main

import “fmt”

func main() {
grade := 70

if grade >= 65 {
fmt.Println(“Passing grade”)
}
}

With this code, we have the variable grade and are giving it the integer value of 70. We are then using the if statement to evaluate whether or not the variable grade is greater than or equal ( >= ) to 65. If it does meet this condition, we are telling the program to print out the string Passing grade.

Save the program as grade.go and run it in a local programming environment from a terminal window with the command go run grade.go.

In this case, the grade of 70 does meet the condition of being greater than or equal to 65, so you will receive the following output once you run the program:
OutputPassing grade

Let’s now change the result of this program by changing the value of the grade variable to 60:
grade.gopackage main

import “fmt”

func main() {
grade := 60

if grade >= 65 {
fmt.Println(“Passing grade”)
}
}

When we save and run this code, we will receive no output because the condition was not met and we did not tell the program to execute another statement.

To give one more example, let us calculate whether a bank account balance is below 0. Let’s create a file called account.go and write the following program:
account.gopackage main

import “fmt”

func main() {
balance := -5

if balance < 0 {
fmt.Println(“Balance is below 0, add funds now or you will be charged a penalty.”)
}
}

When we run the program with go run account.go, we’ll receive the following output:
OutputBalance is below 0, add funds now or you will be charged a penalty.

In the program we initialized the variable balance with the value of -5, which is less than 0. Since the balance met the condition of the if statement (balance < 0), once we save and run the code, we will receive the string output. Again, if we change the balance to 0 or a positive number, we will receive no output.

Else Statements

It is likely that we will want the program to do something even when an if statement evaluates to false. In our grade example, we will want output whether the grade is passing or failing.

To do this, we will add an else statement to the grade condition above that is constructed like this:
grade.gopackage main

import “fmt”

func main() {
grade := 60

if grade >= 65 {
fmt.Println(“Passing grade”)
} else {
fmt.Println(“Failing grade”)
}
}

Since the grade variable has the value of 60, the if statement evaluates as false, so the program will not print out Passing grade. The else statement that follows tells the program to do something anyway.

When we save and run the program, we’ll receive the following output:
OutputFailing grade

If we then rewrite the program to give the grade a value of 65 or higher, we will instead receive the output Passing grade.

To add an else statement to the bank account example, we rewrite the code like this:
account.gopackage main

import “fmt”

func main() {
balance := 522

if balance < 0 {
fmt.Println(“Balance is below 0, add funds now or you will be charged a penalty.”)
} else {
fmt.Println(“Your balance is 0 or above.”)
}
}
OutputYour balance is 0 or above.

Here, we changed the balance variable value to a positive number so that the else statement will print. To get the first if statement to print, we can rewrite the value to a negative number.

By combining an if statement with an else statement, you are constructing a two-part conditional statement that will tell the computer to execute certain code whether or not the if condition is met.

Else if Statements

So far, we have presented a Boolean option for conditional statements, with each if statement evaluating to either true or false. In many cases, we will want a program that evaluates more than two possible outcomes. For this, we will use an else if statement, which is written in Go as else if. The else if or else if statement looks like the if statement and will evaluate another condition.

In the bank account program, we may want to have three discrete outputs for three different situations:

The balance is below 0
The balance is equal to 0
The balance is above 0

The else if statement will be placed between the if statement and the else statement as follows:
account.gopackage main

import “fmt”

func main() {
balance := 522

if balance < 0 {
fmt.Println(“Balance is below 0, add funds now or you will be charged a penalty.”)
} else if balance == 0 {
fmt.Println(“Balance is equal to 0, add funds soon.”)
} else {
fmt.Println(“Your balance is 0 or above.”)
}
}

Now, there are three possible outputs that can occur once we run the program:

If the variable balance is equal to 0 we will receive the output from the else if statement (Balance is equal to 0, add funds soon.)
If the variable balance is set to a positive number, we will receive the output from the else statement (Your balance is 0 or above.).
If the variable balance is set to a negative number, the output will be the string from the if statement (Balance is below 0, add funds now or you will be charged a penalty).

What if we want to have more than three possibilities, though? We can do this by writing more than one else if statement into our code.

In the grade.go program, let’s rewrite the code so that there are a few letter grades corresponding to ranges of numerical grades:

۹۰ or above is equivalent to an A grade
۸۰-۸۹ is equivalent to a B grade
۷۰-۷۹ is equivalent to a C grade
۶۵-۶۹ is equivalent to a D grade
۶۴ or below is equivalent to an F grade

To run this code, we will need one if statement, three else if statements, and an else statement that will handle all failing cases.

Let’s rewrite the code from the preceding example to have strings that print out each of the letter grades. We can keep our else statement the same.
grade.gopackage main

import “fmt”

func main() {
grade := 60

if grade >= 90 {
fmt.Println(“A grade”)
} else if grade >= 80 {
fmt.Println(“B grade”)
} else if grade >= 70 {
fmt.Println(“C grade”)
} else if grade >= 65 {
fmt.Println(“D grade”)
} else {
fmt.Println(“Failing grade”)
}
}

Since else if statements will evaluate in order, we can keep our statements pretty basic. This program is completing the following steps:

If the grade is greater than 90, the program will print A grade, if the grade is less than 90, the program will continue to the next statement…
If the grade is greater than or equal to 80, the program will print B grade, if the grade is 79 or less, the program will continue to the next statement…
If the grade is greater than or equal to 70, the program will print C grade, if the grade is 69 or less, the program will continue to the next statement…
If the grade is greater than or equal to 65, the program will print D grade, if the grade is 64 or less, the program will continue to the next statement…
The program will print Failing grade because all of the above conditions were not met.

Nested If Statements

Once you are feeling comfortable with the if, else if, and else statements, you can move on to nested conditional statements. We can use nested if statements for situations where we want to check for a secondary condition if the first condition executes as true. For this, we can have an if-else statement inside of another if-else statement. Let’s look at the syntax of a nested if statement:
if statement1 { // outer if statement
fmt.Println(“true”)

if nested_statement { // nested if statement
fmt.Println(“yes”)
} else { // nested else statement
fmt.Println(“no”)
}

} else { // outer else statement
fmt.Println(“false”)
}

A few possible outputs can result from this code:

If statement1 evaluates to true, the program will then evaluate whether the nested_statement also evaluates to true. If both cases are true, the output will be:

Outputtrue
yes

If, however, statement1 evaluates to true, but nested_statement evaluates to false, then the output will be:

Outputtrue
no

And if statement1 evaluates to false, the nested if-else statement will not run, so the else statement will run alone, and the output will be:

Outputfalse

We can also have multiple if statements nested throughout our code:
if statement1 { // outer if
fmt.Println(“hello world”)

if nested_statement1 { // first nested if
fmt.Println(“yes”)

} else if nested_statement2 { // first nested else if
fmt.Println(“maybe”)

} else { // first nested else
fmt.Println(“no”)
}

} else if statement2 { // outer else if
fmt.Println(“hello galaxy”)

if nested_statement3 { // second nested if
fmt.Println(“yes”)
} else if nested_statement4 { // second nested else if
fmt.Println(“maybe”)
} else { // second nested else
fmt.Println(“no”)
}

} else { // outer else
statement(“hello universe”)
}

In this code, there is a nested if statement inside each if statement in addition to the else if statement. This will allow for more options within each condition.

Let’s look at an example of nested if statements with our grade.go program. We can check for whether a grade is passing first (greater than or equal to 65%), then evaluate which letter grade the numerical grade should be equivalent to. If the grade is not passing, though, we do not need to run through the letter grades, and instead can have the program report that the grade is failing. Our modified code with the nested if statement will look like this:
grade.go
package main

import “fmt”

func main() {
grade := 92
if grade >= 65 {
fmt.Print(“Passing grade of: “)

if grade >= 90 {
fmt.Println(“A”)

} else if grade >= 80 {
fmt.Println(“B”)

} else if grade >= 70 {
fmt.Println(“C”)

} else if grade >= 65 {
fmt.Println(“D”)
}

} else {
fmt.Println(“Failing grade”)
}
}

If we run the code with the variable grade set to the integer value 92, the first condition is met, and the program will print out Passing grade of:. Next, it will check to see if the grade is greater than or equal to 90, and since this condition is also met, it will print out A.

If we run the code with the grade variable set to 60, then the first condition is not met, so the program will skip the nested if statements and move down to the else statement, with the program printing out Failing grade.

We can of course add even more options to this, and use a second layer of nested if statements. Perhaps we will want to evaluate for grades of A+, A and A- separately. We can do so by first checking if the grade is passing, then checking to see if the grade is 90 or above, then checking to see if the grade is over 96 for an A+:
grade.go…
if grade >= 65 {
fmt.Print(“Passing grade of: “)

if grade >= 90 {
if grade > 96 {
fmt.Println(“A+”)

} else if grade > 93 && grade <= 96 {
fmt.Println(“A”)

} else {
fmt.Println(“A-“)
}

In this code, for a grade variable set to 96, the program will run the following:

Check if the grade is greater than or equal to 65 (true)
Print out Passing grade of:
Check if the grade is greater than or equal to 90 (true)
Check if the grade is greater than 96 (false)
Check if the grade is greater than 93 and also less than or equal to 96 (true)
Print A
Leave these nested conditional statements and continue with remaining code

The output of the program for a grade of 96 therefore looks like this:
OutputPassing grade of: A

Nested if statements can provide the opportunity to add several specific levels of conditions to your code.

Conclusion

By using conditional statements like the if statement, you will have greater control over what your program executes. Conditional statements tell the program to evaluate whether a certain condition is being met. If the condition is met it will execute specific code, but if it is not met the program will continue to move down to other code.

To continue practicing conditional statements, try using different operators to gain more familiarity with conditional statements.

خرید وی پی ان آنتی فیلترآنتی فیلتر

Re: เกมส์ยิงปลาได้เงินจริงกับ ۱۶۸SLOTXO

https://www.slotxd.com/jokergaming123 jokergaming สล็อตออนไลน์ โจ๊กเกอร์123

خرید وی پی ان آنتی فیلترآنتی فیلتر

How to Install RaspEX Kodi on the Raspberry Pi

The guide below will show you how to install RaspEX on a Raspberry Pi. I am using an RPi 4 (4GB) but it will also work on RPi 4 (1&2GB) 3/3B+, and 2. If you are installing just to use Kodi then the lower versions are fine but if you really want to get more out of this then the RPi4 4GB is highly recommended. If it is just for Kodi then the lower versions are fine. But this is a great way of making a cheap home computer.
RaspEX Kodi is based on Debian, Raspbian and Kodi Media Center. In RaspEX Kodi the dev has added the LXDE Desktop with many useful applications such as VLC Media Player and NetworkManager. This makes it easy to configure your wireless network. The dev has also upgraded Kodi to version 18.3 “Leia”, which makes it possible to include useful addons such as Netflix, Plex and Amazon Video.

Items Required:

Raspberry Pi (Raspberry Pi 4 recommended)
Case
Power supply
MicroSD card (8GB+ Recommended)
HDMI cable
Monitor
Internet connection
keyboard & mouse
Image mounting software like Etcher

How to Install RaspEX Kodi:

Set your RPi up: Add keyboard and mouse (you can get cheap wireless ones online), connect to monitor, plug in power supply, add ethernet connection, you can also use a wifi dongle and connect to the internet by clicking on the network symbol top right when RaspEX is installed
Place your microSD card in your PC/Mac as we need to install the image to this later
Download RaspEX Kodi (2.3GB Download)
Unzip the RaspEX Kodi file so you have a .img file

If you don’t have any image mounting software then go to Techspot and download a version of Etcher that is suitable for the computer you are using

Install the version of Etcher you have just downloaded, open it and select Select Image

Navigate to where you extracted the RaspEX Kodi .img file and select it

Etcher should now show details of the image file.

Now select Select target and then choose your microSD card and select Continue. You may not need to do this as Etcher may have already detected your card. You can also click on change here if it has picked up an incorrect card

Now select Flash and let Etcher do its thing

The install will probably take an hour or so. So go and pour yourself a tipple, take your dogs for a walk or do something else you enjoy whilst it flashes. Once flashed Validation of the file will begin to ensure everything is ok

If completed correctly you will see a message saying Flash Complete – 1 Successful Device

Now eject the microSD from your computer and place it into the microSD slot on your RPi and the installation will begin and then you will see the RaspEX desktop. You can now begin using it as a desktop computer or get Kodi up and running

I recommend using a VPN to help keep yourself anonymous and protect yourself online. You can get 25% off any package from IPVanish & 20% off any Strong VPN Package which allow you to connect 5 devices to an encrypted VPN connection at any one time.

Native apps for Android TV, Android, iOS, Mac, Linux, and more OS’
Access all Kodi add-ons anonymously
Tier 1 hardware (no speed slowdown)
Prevent ISP Throttling
Log-free, so you can’t be tracked
۷ day money back guarantee
The ability to be configured right at your router, for a hassle-free experience.

You can use these links to get an extra discount to try a VPN out

IPVanish
StrongVPN

خرید وی پی ان آنتی فیلترآنتی فیلتر

How to Remove Slide Numbers from PowerPoint Slides

Slide numbers are a great way to navigate to a specific slide on your PowerPoint presentation quickly. In the event that the slide numbers are no longer necessary, you might want to remove them. Here’s how.
Remove Slide Number from One or All Slides
First, open the PowerPoint presentation that contains the slide numbers you want to remove. The slide number appears in the top-left corner of its respective slide.

Next, head over to the “Text” group of the “Insert” tab and select “Slide Number.”

Once selected, the “Header and Footer” dialog box will appear. In the “Slide” tab, uncheck the box next to “Slide Number.” If you want to remove the number from only the selected slide, then select “Apply” (2). If you want to remove the numbers from every slide in the presentation, then select “Apply to All” (3).

Remove Slide Number from Title Slide
You might want to remove the slide number from the title slide only. Numbering that slide probably isn’t necessary as most understand the title slide is the first slide of your presentation.
Read the remaining 5 paragraphs

خرید وی پی ان آنتی فیلترآنتی فیلتر

How to Set the Default Finder Folder on Your Mac

Khamosh Pathak
Finder is your window to the Mac file system. Every time you open Finder, it defaults to the Recents folder. But if you usually save your work in a different folder, you might want to change the button’s default behavior.
First, open the Finder app by clicking on the button in the Dock that looks like a face. From the menu bar, click on the “Finder” option. Next, click on “Preferences.” Alternatively, you can use the “Command+,” (Command key and the comma) keyboard shortcut to quickly open the Preferences window.

In this window, select the “General” tab and then locate “New Finder Window Show.” Click on the drop-down menu below the option.

From here, you can select from a list of pre-defined options. You’ll find the iCloud Drive, Desktop, and Documents folders here.
You can also click on the “Other” option and choose any folder from the file directory (for instance, the Downloads folder).

Browse through the file directory and select the folder you want as the default. Then click on the “Choose” button.
Read the remaining 6 paragraphs

خرید وی پی ان آنتی فیلترآنتی فیلتر